Site logo

Archived topic

Display Posts Randomly on Homepage?

7 replies · Started by Daniel on August 28, 2020

Viewing posts 1–8 of 8

Hi there,

Good find!

Try this instead:

add_action( 'pre_get_posts', 'generate_random_posts', 100 );
function generate_random_posts( $query ) {
    if ( $query->is_main_query() ) {
        $query->set( 'orderby', 'rand' );
    }
}

Thank's it seems to work but it displays double posts sometimes. Any way to fix that?

No same thing happens, any other ideas?

Hmm does the same issue happen if you disable the infinite scroll option?

Yes the same thing happens.

That's strange. Any chance you can check with WordPress support to see if they have any ideas?

If they can provide the code that works in a twenty series default theme, it would work in GP as well as the post loop is completely handled by WordPress :)

This archived topic is closed to new replies.