0

I have a buddypress with a theme (youzify), I want to display activity posts randomly on home page, not in chronological order. Anyone knows any code or method for that?

I used this code but it doesn't work buddypress

function posts_random_order( $query ) {

    if ( $query->is_main_query() && $query->is_home() ) {

        $query->set( 'orderby', 'rand' );

    }

}

add_action( 'pre_get_posts', 'posts_random_order' );

1 Answer 1

0

And why not using simple wordpress code, changing args ?

$args = array(
        'post_type'      => 'post',
        'orderby'        => 'rand',
        'posts_per_page' => '1',
    );
    $my_query = new WP_Query( $args );
    if ( $my_query->have_posts() ) {
        while ( $my_query->have_posts() ) {
            $my_query->the_post();

            /* do your post output here */

        } // end while
    } // end if
2
  • This code does not work with buddypress
    – wmasat
    Commented Aug 1, 2023 at 14:44
  • Hi, what is the error shown ?
    – Aurel
    Commented Feb 14 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.