I’m trying to display the 5 best rated posts of the last week (7 days) on my website, however I can’t seem to figure out how to display them.
Here’s what I’ve achieved so far but it doesn’t seem to work:
<?php $slider_query = new WP_Query('posts_per_page=5&cat=3&orderby=highest_rated&order=desc'); ?>
<?php
$mylimit = 7 * 86400; //days * seconds per day
while ($slider_query->have_posts()) : $slider_query->the_post();
$post_age = date('U') - get_post_time('U');
if ($post_age < $mylimit) {
?>
//The Post
<?php } ?>
<?php endwhile;?>
In addition to birgire’s solution, as of WordPress 3.7, you can use Date parameters.
Your arguments would look like this to filter posts from the last 7 days:
I think this must have been solved many times here on WordPress Answers.
You could also check out the examples in the Time parameters part in Codex for
WP_Query
.Here are two of them (slightly modified to your needs)
Example 1:
Example 2:
assuming that you have this
orderby=highest_rated
covered with some plugin as you describe in the comment above.From the
WP_Query
Time Parameters section:Returns posts for just the current week:
Working for me like this, to show post from last 7 days according to the number of views and order by post views count DESC.
you can simply use wp_get_archives()
More Simple Using sql query wordpress hook posts where