Can someone help me how to display the post only for a week? i have this code that works fine in post_date:
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'cat' => 1,
'orderby' => 'date',
'order' => 'DESC',
// Using the date_query to filter posts from last week
'date_query' => array(
array(
'after' => '1 week ago'
)
)
);
?>
<ul class="weekly-list">
<?php $the_query = new WP_Query( $args ); ?>
<?php while ( $the_query->have_posts() ) { $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php } wp_reset_postdata(); ?>
</ul>
but how to do it in the custom field date. Because my other events is posted a week before the events. Can someone help me?
Thanks.
This Might help you to get solution:
The previous answer was along the good track. Just modify your
date_query
: