Files
2024_WEBSITE_fipf/plugins/cipf_plugin/php/random_posts.php
2024-03-31 19:59:20 +02:00

41 lines
710 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::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::debug_infos();
$query->set('orderby', 'rand');
}
add_action('pre_get_posts', 'randomize_post_output_CIPF');
?>