1

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.

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
?>

Edit: I updated this answer based on input from @birgire to behave more performant.

  • Nice idea, but since you are fetching all the author's posts, let's hope they aren't too many ;-) You could for example add the parameter 'fields' => 'ids' to reduce the amount of fetched data. – birgire Jan 24 '14 at 4:39
  • 1
    ps: here's an attempt to extend the WP_Query() to return only the number of results. – birgire Jan 24 '14 at 4:54
0

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.

  • Yeah, I think for my current situation I'll go with this, but eventually build out my own. Thanks – mazing Jan 26 '14 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.