【发布时间】:2021-12-14 12:32:15
【问题描述】:
使用下面的代码, 我设法获得每位作者的帖子数量。 如何向此查询添加类别过滤器“neuws”。 为了计算“新闻”类别中作者的帖子数量 感谢您的帮助
<?php
//pour voir les journees de peches de mebres en ayant deja postees et le nombre de journees
// 1. We define the arguments to define what we want to recover
$args = array (
'post_type' => 'post',
'posts_per_page' => '16',
);
// 2. We run the WP Query
// The Query
$the_query = new WP_Query ($args);
// 3. we display the number of messages and the authors!
// The Loop
if ($the_query-> have_posts()) {
//Set arguments to grab all authors with published peches, and order them by user ID
$authorArgs = array(
'orderby' => 'ID',
'has_published_posts' => array('post',),
);
//Create an array of all authors with peches published
$pecheAuthors = get_users($authorArgs);
//Loop through each peche author
foreach($pecheAuthors as $user){
//Output user post count for peches
echo'<font color="#f00;"><b>';
echo count_user_posts($user->ID, 'post');
echo'</b></font>';
echo ' journees de pêches pour ';
//Output user's display name
echo'<font color="#f00;"><b>';
echo $user->display_name;
echo'</b></font>';
echo '<br />';
}
// 3. We launch the loop to display the articles and the authors!
// The Loop
} else {
// no posts found
}
//wp_reset_postdata ();?
?>
【问题讨论】: