我使用WP\\u User\\u查询查询了一个用户列表,从中我获得了头像、名称和一些我为用户注册创建的ACF。
现在,我需要获得结果中每个用户的帖子列表,但我不知道怎么做。
这是我在WP\\u User\\u query中的查询:
$postArgs = array (
\'author__in\'=> array(2,4,6), //Authors\'s id\'s you like to include
\'post_type\' => \'post\',
\'posts_per_page\' => 5,
);
$postsquery = new WP_Query ( $postArgs);
while ( $postsquery->have_posts() ) : $postsquery->the_post();
echo \'
<li class="viral-note">
<div class="row no-gutter">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3"> <img src="\' . get_the_post_thumbnail_url() . \'" alt="" class="square-mini img-responsive"> </div>
<div class="col-xs-8 col-sm-8 col-md-8 col-lg-8">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <span class="catego-tag">\' . $category[0]->cat_name . \'</span> </div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12"> <span class="excerpt">\' . get_the_title() . \'</span> </div>
</div>
</div>
</li>\';
endwhile;wp_reset_query();
如何将第一个查询中的用户存储到数组中,然后将其传递到第二个查询中?
SO网友:dryan1144
如果你通过fields
用户查询的参数您可以轻松获取ID数组,以传入wp查询:
//WP User Query
$author_query = new WP_User_Query( array (
\'number\' => 3,
\'fields\' => \'ID\'
));
$author_results = $author_query->results;
//WP Query
$postArgs = array (
\'author__in\'=> $author_results,
\'post_type\' => \'post\',
\'posts_per_page\' => 5,
);