I'm working on a site that has blog posts with performers' info under a single category that can be filtered using a custom taxonomy (both parent and child terms). To keep it as fair as possible, the site owners would like the category and filter results display to be in random order. This is what I was able to find to 'randomize':
add_action( 'pre_get_posts', 'my_change_sort_order');
function my_change_sort_order($query){
if(is_category('artstour-roster') OR is_tax('artistic_disciplines') OR is_tax('geographic_availability') OR is_tax('additional_services') OR is_tax('core_audiences') OR is_tax('additional_populations')):
//Set the order ASC or DESC
$query->set( 'order', 'ASC' );
//Set the orderby
$query->set( 'orderby', 'rand' );
endif;
};
This displays the post excerpts in random order with 6 per page. However, if you have more than one page of results and move between pages, the number of results stays the same, but moving to the next or previous page gives a new random order, which causes repeats and omissions.
For example, a filter of the 'A cappella' child taxonomy term produces 7 results. When moving to the second page of results, only one result entry is displayed, but that single result is randomized again, showing one of the results previously seen on the prior page and thereby leaving one of the filtered excerpts omitted from the filter results entirely.
Is there a way to 'lock in' the randomized result set across pages?