0

I have a standard loop and I want to by the author's name show how many posts were published for the current day by an author.

1

I'm not where I can run the below, but potential typos, etc. aside, it should be able to point you in the right direction.

1) Limit Query

You could add Date Parameters to your query arguments to limit them.

$today = getdate();
$args = array(
    'date_query' => array(
        array(
            'year'  => $today['year'],
            'month' => $today['mon'],
            'day'   => $today['mday'],
        ),
    ),
    'posts_per_page' => -1,
);
$query = new WP_Query( $args );
$posts = $query->posts;

2) Build author_id => post count array

Then get all the author ids as array keys to force unique entries, and count as value:

$authors = array();
foreach( $posts as $post ) {
   if ( array_key_exists( $post->post_author ) {
        $authors[$post->post_author] = ++$authors[$post->post_author];
   }
   else {
        $authors[$post->post_author] = 1; 
   } 
}

3) echo author name and count

Then loop through that array to get the values:

foreach ( $authors as $author ) {

   // since the key is the numeric id, we will use it to get display name
   echo get_the_author_meta( 'display_name', key($author) ) .': '. $author;
}
5
  • I think you have my question wrong. I am trying to get the users published post count. (ex. Tracy Woods - 10 Posts Today, Nicholas Walker - 3 Posts This Week) – user73579 Aug 2 '17 at 22:32
  • Sorry, I was going off of The function below only gives you all of the authors posts, but I just only want to display post(s) for the current day. – hwl Aug 2 '17 at 23:03
  • Since you have rephrased this question elsewhere and received a rather complete answer over there, I would just delete this question so it doesn't hang around unanswered. birgire's answer seems rather complete. – hwl Aug 3 '17 at 14:02
  • I can rephrase this question to fit your answer and mark complete instead of deleting in case someone is looking for your answer. – user73579 Aug 3 '17 at 14:08
  • Yeah you're probably right on that. Cool. :) – hwl Aug 3 '17 at 14:10

Your Answer

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