admin管理员组文章数量:1134246
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' );
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' );
Share
Improve this question
edited Aug 1, 2023 at 5:42
Arsalan Mithani
5534 silver badges15 bronze badges
asked Jul 29, 2023 at 15:48
wmasatwmasat
11 bronze badge
1 Answer
Reset to default 0And 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
本文标签: pluginsRandomly display activity posts on home page with buddypress
版权声明:本文标题:plugins - Randomly display activity posts on home page with buddypress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736853523a1955612.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论