Home › Forums › ACF PRO › Expire Posts › Reply To: Expire Posts
Could you not condense the query down to something like:
function listing_expiry_date() {
$args = array(
'post_type' => array('post_type_listings'),
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'post_date',
'order' => 'DESC',
'date_query' => array(
array(
#'after' => 'January 1st, 2013',
'before' => array(
'year' => date("Y"),
'month' => date('m'),
'day' => date('d'),
),
'inclusive' => true,
),
),
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
# change the post status
$postdata = array(
'ID' => $post->ID,
'post_status' => 'expired'
);
wp_update_post($postdata);
}
wp_reset_postdata();
}
}
Code untested!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.