Note that the posts_orderby
filter is not available for get_posts()
where suppress_filters
is true
by default.
You can use WP_Query
instead:
$args = [
'posts_per_page' => 1,
'orderby' => 'rand',
'post_type' => 'listing',
'ignore_sticky_posts' => true,
];
add_filter( 'posts_orderby', 'force_random_day_seed' );
$q = new WP_Query( $args );
remove_filter( 'posts_orderby', 'force_random_day_seed' );
if( $q->have_posts() )
{
while( $q->have_posts() )
{
$q->the_post();
the_title();
}
wp_reset_postdata();
}
else
{
_e( 'Sorry no posts found!' );
}
It’s also possible to skip your posts_orderby
filter callback and just use transients to store the results for 24 hours.