Hi, @wmasat! I was going to direct you to BuddyPress support, but I see that you’ve already posted there.
For some more general advice, WordPress has built-in support for randomizing post order. Here’s some example code and references to code documentation to get you started.
<?php
$args = array(
'post_type' => 'your_custom_post_type', // replace with your custom post type slug
'posts_per_page' => X, // replace with the number of posts you want to display
'orderby' => 'rand'
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// Template for displaying the post
// For example, you could display the post title like this:
echo '<h2>' . get_the_title() . '</h2>';
// Add more output as per your needs.
}
} else {
// If no posts match this query, output this text.
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
}
wp_reset_postdata();
?>
Keep in mind that the ‘rand’ orderby parameter can be somewhat slow if you have a lot of posts.
-
This reply was modified 1 year, 7 months ago by
Zack Krida. Reason: fix some formatting