WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I managed to loop my posts in a page template, ordering the posts by most viewed.

The query posts string looks like this

$wplover_home = new WP_Query('posts_per_page=18&v_sortby=views&v_orderby=desc&paged=' . $paged);

while ($wplover_home->have_posts()) : $wplover_home->the_post(); ?>

Now to my question. If I wanted to sort the posts by most viewed in X days or months, how should the string look like then? The documentation for the plugin (wp-postviews) doesn't have anything on this.

Thanks in advance :-)

share|improve this question

Not sure exactly what you mean by "x days or months", but I'm assuming you want to set a time interval for the posts that you are querying. I would recommend that you take a look at the "Time Parameters" section in the Codex article on WP_Query. It does an excellent job explain how to limit the query by day, month, year, or for a specific interval. If you have a question after reviewing that, I'd be happy to help.

share|improve this answer
Thanks for that. But adding day=7 to the query string just shows posts from the last 7 days - not the most watched posts in the last 7 days :-) As started below, it is not possible. What a shame :( – Torben Feb 12 '12 at 21:12
Oh...yep...that would be a big problem. Have you looked into using JetPack which provides you with WordPress.com stats and a handy API for getting such information? – tollmanz Feb 12 '12 at 21:19

If you wanted to sort by only the views in the past XX days. It is not possible, as the plugin does not record the date. More information here.

share|improve this answer
Oh no, thats bad. Do you know of any alternative method to do so? – Torben Feb 12 '12 at 21:11
Try wordpress.org/extend/plugins/recent-post-views. You will have to look into the source for the query, though. – imHavoc Feb 12 '12 at 21:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.