0

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 :-)

2 Answers 2

1

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.

2
  • 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
    Commented Feb 12, 2012 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
    Commented Feb 12, 2012 at 21:19
0

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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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