$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Display Published Posts Count for Certain Time Period|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Display Published Posts Count for Certain Time Period

matteradmin9PV0评论

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

Post a comment

comment list (0)

  1. No comments so far