Show amount of posts created today above loop?

I think I have figured out the most efficient way to do this. The tricky part is that you need the query for posts within the date range to:

A. Match the current query. If you’re looking at a category or tag, you want to get the posts from that day in that category or tag.

B. Not be limited by the current posts-per-page setting. If you post more than one page’s worth of posts in a day, the number needs to reflect that.

You also don’t need to query all the post data associated with these posts. You’re just after the count.

The solution I’ve come up with is:

  1. Get the current query.
  2. Turn of pagination.
  3. Set it to return just post IDs.
  4. Add a date query to limit it to posts from the current day.

It has been tested and works well.

To do this, we can access global $wp_query then get $wp_query->query_vars for the current query arguments. Then we modify the arguments as I described above and pass the new arguments to get_posts(). Then we just count the results. This is a function that does this:

function wpse_287363_get_posts_today_count() {
    global $wp_query;

    // Get query arguments for current main query.
    $args = $wp_query->query_vars;

    // Set new values for relevant arguments.
    $arg_amendments = array(
        'fields'     => 'ids',
        'nopaging'   => true,
        'date_query' => array(
            array(
                'after'     => 'today',
                'before'    => 'tomorrow - 1 second',
                'inclusive' => true,
            ),
        ),
    );

    // Replace relevant arguments in existing arguments with amended arguments.
    $new_args = array_merge( $args, $arg_amendments );

    // Get posts with new arguments.
    $post_ids = get_posts( $new_args );

    // Count results.
    $count = count( $post_ids );

    // Return count.
    return $count;
}

Now you can use wpse_287363_get_posts_today_count() to get the number of posts made on the current date, relevant to whichever archive you’re viewing.

So if you’re on a category archive it will return the number of posts made today in that category. On a tag archive it will return the number of posts made today in that tag. It will even work on date archives and show the number of posts made today in a given year/month. If you’re just on the blog page it will show the number of posts made today in any category or tag. It should even work with custom post type/taxonomy archives.