Display Published Posts Count for Certain Time Period

admin2025-06-03  2

I need some kind of plugin (if it exists) or a wp query which would display number of posts published within a certain time range.

For example:

I need to know how many posts have been published since 2015-06-01 until now -- 2015-06-27.

I really hope someone could help me out.

Thanks.

I need some kind of plugin (if it exists) or a wp query which would display number of posts published within a certain time range.

For example:

I need to know how many posts have been published since 2015-06-01 until now -- 2015-06-27.

I really hope someone could help me out.

Thanks.

Share Improve this question asked Jun 27, 2015 at 9:36 IGNASIGNAS 711 silver badge3 bronze badges 1
  • Please elaborate your question and show us what have you tried so far. – Nilambar Sharma Commented Jun 27, 2015 at 10:33
Add a comment  | 

2 Answers 2

Reset to default 1

You can fetch the record using bellow query

$posts= get_posts(array(
            'numberposts' => -1,
            'post_status' => 'publish',
            'orderby' => 'date',
            'order'   => 'DESC',
            'date_query'    => array(
                'column'  => 'post_date',
                'after'   => '-7 days'  // -7 Means last 7 days 
            )
        ));
echo count($posts);

If you want to get last 6 month the use -6 Months

see also User Published Post Count

if you've got many posts, you may want to use WP Query

date_query has been available since version 3.7

$args = [
    'author' => $user_id, 
    'posts_per_page' => 1, //don't need more
    'fields' => 'ids', //don't need more
    'suppress_filters' => true, 
    'date_query' => ['after' => '-6 months']
];

$query = new WP_Query( $args );  
$count_per_author = $query->found_posts; //how many posts match the query args

post_count is used for how many posts are displayed

for between date A and date B, you can use

'date_query' => [
    'after' => '1 January 2019',
    'before' => '31 January 2019'
],

'inclusive' => true,

see the WP Codex for more details on WP Query, inc. examples of how to use the date args and inclusive to match exact date values

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748919362a314818.html

最新回复(0)