admin管理员组文章数量:1333485
I've searched around and have had no luck or success in finding a way to show how many posts an author has made in a certain period of time (e.g. - a week)
Any ideas on how one would approach this? I just want to display the total number of posts an author has made in a given time period.
I've searched around and have had no luck or success in finding a way to show how many posts an author has made in a certain period of time (e.g. - a week)
Any ideas on how one would approach this? I just want to display the total number of posts an author has made in a given time period.
Share Improve this question edited Jan 24, 2014 at 4:47 Jan Beck 1,46711 silver badges17 bronze badges asked Jan 24, 2014 at 1:26 mazingmazing 1253 bronze badges2 Answers
Reset to default 1Have a look on the date_query parameter that has been added to WP 3.7 WP_Query#Date_Parameters and the author parameter.
Combine the two parameters as you need them to query all posts an author created in a given time:
<?php
$args = array(
'posts_per_page' = -1, // get all posts
'author' => get_the_author_meta( 'ID' ), // from this author ID
'date_query' => array( // in the last week
array(
'year' => date('Y'),
'week' => date('W'),
),
'fields' => 'ids' // only return an array of post IDs
),
);
$results = new WP_Query( $args );
echo count( $results ); // display the number of results
echo $results->found_posts; // display the number of results
?>
Edit: I updated this answer based on input from @birgire to behave more performant.
You could use a plugin such as Author Stats to pull out those statistics.
If you want something more custom you'll have to write your own widget or plugin.
本文标签: wp queryHow can I show many posts an author has per week
版权声明:本文标题:wp query - How can I show many posts an author has per week? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742341106a2456619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论