Forums › Forums › Search & Filter Pro › Random is not Random
- This topic has 3 replies, 2 voices, and was last updated 9 years, 10 months ago by Ross.
-
Ross Moderator(Private) December 16, 2014 at 10:13 pm #9153
Hey Robbin,
We use the
random
option as defined by WP – http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_ParametersI suspect you may have some custom code or another plugin that is interfering with the search results? – anything that modifies queries or uses the
pre_get_posts
hook could do this.If you choose another option, other than random, do you find that the results are still ordered the same?
Thanks
Anonymous(Private) December 18, 2014 at 2:57 pm #9258Thanks for your reply.
All of our other sort options are displaying in the correct order and the random order is working when set as the default display.
However, when set as a sorting option it displays a in the same order as descending by date.
I should mention that to get the random by default setting to work, I had to add this to the functions.php file:
session_start(); add_filter( 'posts_orderby', 'randomise_with_pagination' ); function randomise_with_pagination( $orderby ) { if( is_front_page() || is_page(5020) ) { // Page 5020 is the page the form is on. // Reset seed on load of initial archive page if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) { if( isset( $_SESSION['seed'] ) ) { unset( $_SESSION['seed'] ); } } // Get seed from session variable if it exists $seed = false; if( isset( $_SESSION['seed'] ) ) { $seed = $_SESSION['seed']; } // Set new seed if none exists if ( ! $seed ) { $seed = rand(); $_SESSION['seed'] = $seed; } // Update ORDER BY clause to use seed $orderby = 'RAND(' . $seed . ')'; } return $orderby; }
Ross Moderator(Private) January 8, 2015 at 5:26 pm #9962Hey Robbin, I investigated this further and there does indeed appear to be a bug with this – I’ll include a fix in the next update.
Thanks
-
AuthorPosts