Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to get posts published in the last 30 days using WP_Query
<?php
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'post',
'order'=>'DESC',
'posts_per_page' => 12,
'date_query' => array(
array(
'after' => '-30 days',
'column' => 'post_date',
),
),
'paged' => $paged
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
// LOOP CONTENT HERE
endwhile;
?>
<?php wp_pagenavi( array( 'query' => $loop ) ); ?>
<?php
wp_reset_query();
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.