Support

Account

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!