Dear Kriesi,
Is it possible to see the search results from posts in a random order?
Thanks in advance,
Pieter
Hi pieterpieterpieter!
You can add this to the bottom of your functions.php file.
add_filter( 'pre_get_posts', 'enfold_customization_random_search' );
function enfold_customization_random_search( $q ) {
if ( $q->is_search ) { $q->set( 'orderby', 'rand' ); }
return $q;
}
Though I’m not sure why you would want to do that. It defeats the purpose of searching.
Cheers!
Elliott
Hmm it doesn’t work.
I have already managed to show my search results in a grid.
Now i just need to make it random. Why? Because it’s a restaurant listing website. I want to show them random so it’s not always the same restaurant first you see?
Thanks!
Pieter
Thank God i found a solution!
For anyone with this problem:
Add this to your functions.php file.
function random_search_result( $q ) {
if ( is_search() && is_main_query() )
$q->set( ‘orderby’, ‘rand’);
}
add_action( ‘pre_get_posts’, ‘random_search_result’ );
That’s it!
Thanks for the support Kriesi! Fantastic like always!
Pieter