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