Now Working with Wp Query – Thanks to Milo in the comments
add_action('cvl_job_status_cron', 'cvl_mark_as_expired');
function cvl_mark_as_expired() {
global $post;
$args = array(
'post_type' => array( 'job_listing' ),
'posts_per_page' => '-1',
'fields' => 'ids',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'cvl_job_status',
'terms' => 'live',
'field' => 'slug',
'include_children' => false,
),
),
);
// $post_ids = get_posts($args);
$post_ids = new WP_Query( $args );
if ( $post_ids->have_posts() ) {
while ( $post_ids->have_posts() ) {
$post_ids->the_post();
$post_id = get_the_ID();
$key = 'cvl_job_expires'; // custom field anme
$expire_date = get_post_meta($post_id, $key, true); // Now saved as Unix Timestamp
$todays_date = time(); // get todays date
if ($expire_date < $todays_date) {
$taxonomy = 'cvl_job_status';
$tag = array( 159 ); // 'Expire' tag id is 159
wp_set_post_terms( $post_id, $tag, $taxonomy );
}
}
}
}