42 lines
785 B
PHP
42 lines
785 B
PHP
<?php
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
* randomize post output
|
|
* posts are to randomize if the query ask for a negative number of posts
|
|
* -1 is already used by worpdress to means ALL posts
|
|
* -> so this randomization will not work for 1 post
|
|
*
|
|
*/
|
|
function randomize_post_output_CIPF($query) {
|
|
PLGNTLS_class::debug_infos(2);
|
|
$posts_per_page = $query->get('posts_per_page');
|
|
if (is_null($posts_per_page)) {
|
|
return;
|
|
}
|
|
if ($posts_per_page >= -1) {
|
|
return;
|
|
}
|
|
PLGNTLS_class::debug_infos();
|
|
|
|
error_log("posts_per_page: " . json_encode($posts_per_page));
|
|
$query->set('orderby', 'rand');
|
|
}
|
|
add_action('pre_get_posts', 'randomize_post_output_CIPF');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|