[英]In Wordpress dashboard, how can I make specific user role post only in specific post category?
[英]how can I display specific user's post in wordpress?
我想在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
我该怎么做? 谢谢答案
您可以尝试看看是否可行吗?
$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' );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.