How can I show many posts an author has per week?

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.

Related posts

2 comments

  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.

  2. 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.

Comments are closed.