我想在wordpress中显示热门用户的帖子,我可以通过此代码获得热门用户ID;
$user_query = new WP_User_Query( array(
'meta_query' => array (
array (
'key' => 'wp_popular_users',
'value' => $user_id,
'compare' => 'LIKE'
)
) ) );
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo $user->ID. ', ';
}
}
我可以用这段代码显示帖子;
$the_query = new WP_Query( array(
"posts_per_page"=>8,
"post_type"=>"post",
'author__in'=> array(POPULAR USER IDS HERE!!!),
"paged"=>$paged
) );
while ( $the_query->have_posts() ){
$the_query->the_post();
get_template_part( 'template-parts/content', 'profile-post' );
}
但我无法合并这两个代码,我需要在 'author__in'=>中插入用户IDS数组(热门用户ID在这里!!!), 例如:1,5,7
我该怎么做?谢谢你的答案
答案 0 :(得分:1)
你能试着看看这是否有效吗?
$popularUsers = Array();
$user_query = new WP_User_Query( array(
'meta_query' => array (
array (
'key' => 'wp_popular_users',
'value' => $user_id,
'compare' => 'LIKE'
)
) ) );
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo $user->ID. ', ';
$popularUsers[] = $user->ID;
}
}
$the_query = new WP_Query( array(
"posts_per_page"=>8,
"post_type"=>"post",
'author__in'=> $popularUsers,
"paged"=>$paged
) );
while ( $the_query->have_posts() ){
$the_query->the_post();
get_template_part( 'template-parts/content', 'profile-post' );
}