Skip to content

Displaying only articles from the last week in WordPress

Warning: this article was written over 10 years ago, some information may be out of date.

Small but powerful trick reported by WpRecipes: a filter to show only articles from the last week.
Copy and paste the following code:

$query_args = array(
'w'    => date( 'W' ),
'year' => date( 'Y' ),
);
$posts = get_posts( $query_args );

Before the code that displays the results (the so-called loop).
Enjoy

Previous article

Next article

Thread

Leave a comment

Your email address will not be published.