cipf v 0.4.4 added randomization for posts if < -1
This commit is contained in:
@@ -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');
|
||||
|
||||
|
||||
|
||||
|
||||
41
plugins/cipf_plugin/php/random_posts.php
Normal file
41
plugins/cipf_plugin/php/random_posts.php
Normal 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');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user