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
1
  • This code does not work with buddypress
    – wmasat
    Aug 1 at 14:44

Your Answer

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

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