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 badges
Add a comment  | 

2 Answers 2

Reset to default 1

Have 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