I’d like to create a query to show the top 6 most read posts over the last two days. However, I’d like to only include posts created within the last month to prevent older stories from showing up.
I am using Jetpack and wordpress.com stats, so I’ve created this query for Top Posts, but I’m unsure whether it is the correct approach
$top_posts = stats_get_csv('postviews', 'period=month&days=2&limit=6')
My primary confusion is with the stats_get_csv API period parameter, and how it is used / what the effects are.
While researching to answer this SO Question, stumbled upon this one, which gave me the final hint.
I’ll reproduce the relevant part:
For what I understood of this documentation, using
period=week&days=1&limit=-1'
will return all posts from 1 week period. If we usedays=2
it will be a 2 weeks period.One week seems to be the shortest period. You would have to compare Jetpack results with your internal query of only two days and filter the results.
Take that developers note seriously, as it looks I broke my daily (hopefully) quota while testing. The function is not returning results anymore and even preventing my code from running… Nothing breaks, but simply don’t run.