cipf v 0.4.4 added randomization for posts if < -1

This commit is contained in:
asus
2024-03-27 18:54:57 +01:00
parent 50c05df2b6
commit 42e8cbc4e9
3 changed files with 43 additions and 1 deletions

View File

@@ -50,6 +50,7 @@ include_once(PLGNTLS_class::root_path() . 'php/partners_page.php');
include_once(PLGNTLS_class::root_path() . 'php/display_css.php');
include_once(PLGNTLS_class::root_path() . 'php/payments.php');
include_once(PLGNTLS_class::root_path() . 'php/email_registration.php');
include_once(PLGNTLS_class::root_path() . 'php/random_posts.php');

View File

@@ -0,0 +1,41 @@
<?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');
?>