Yes, if you’re using the latest release there’s a way to do this.
This is not documented and exposed yet. But if you look into includes/query.php you’ll find that we’ve extended WP_Query with extra ‘views_query’ parameter. What that mean is that you can take any post/posts, call regular WP_Query class and provide the date for which get post views count.
Example:
// get views for given period
$args = array(
'post_type' => array( 'post' ),
'posts_per_page' => -1,
'orderby' => 'post_views',
'suppress_filters' => false,
'views_query' => array(
'year' => 2015,
'month' => 11,
'day' => 18
)
);
$posts = get_posts( $args );
Each post returned will include additional ‘post_views’ field that will be the count of views for the requested period.
If you want to have the result for one post only, you may just add p => 1, where 1 is the ID of the post.
Hope this helps.
Regards,
Bartosz
dfactory team