Back in 2017, I was setting up a portfolio site that used posts to display work samples. The forum thread about this is here: https://generatepress.com/forums/topic/randomizing-post-order-on-posts-page/
Part of the solution to my problem came from here: https://wordpress.stackexchange.com/questions/31647/is-it-possible-to-paginate-posts-correctly-that-are-random-ordered/33275#33275
Unfortunately, that code now creates another problem: It interferes with Site Health in WordPress. (The “session_start” was the clue.)
“An active PHP session was detected,” Site Health reports, among other things, chiding me for “critical information about your WordPress configuration and items that require your attention.”
My question is pretty simple: Does WP do a better job of randomizing post display than it did in 2017? Can I remove the following code from my child theme?
session_start();
add_filter('posts_orderby', 'edit_posts_orderby');
function edit_posts_orderby($orderby_statement) {
$seed = $_SESSION['seed'];
if (empty($seed)) {
$seed = rand();
$_SESSION['seed'] = $seed;
}
$orderby_statement = 'RAND('.$seed.')';
return $orderby_statement;
}
function tu_rand_posts( $query ) {
if ( $query->is_main_query() && ! is_admin() ) {
$query->set( 'orderby', 'rand' );
}
}
add_action( 'pre_get_posts', 'tu_rand_posts' );