Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Auto move acf value & update tax term based on custom date WordPress

  • SOLVED

Trying to automatically update some custom post meta fields and taxonomy term based on a custom field $auction_date (if it has passed). Any thoughts? This code will go directly into the custom post type template.

function new_lots_values ( ) {

$date_now = date('Y-m-d H:i:s');

$posts = get_posts(array(
'meta_query' => array(
array(
'key' => 'auction_date',
'compare' => '<',
'value' => $date_now,
'type' => 'DATETIME'
)
),
));

if( $posts ):


//* Move custom field value from $current_catalog to $past_catalog ??

<code goes here>

//* Remove taxonomy term from current-auction taxonomy ??

wp_delete_term( $term, 'current-auction' );

add_action( 'save_post', 'new_lots_values' );

}

Answers (1)

2016-10-08

Rempty answers:

You need to create a cron hook


if ( ! wp_next_scheduled( 'change_term' ) ) {
wp_schedule_event( time(), 'hourly', 'my_cronhook' );
}
add_action( 'my_cronhook', 'change_term' );

function change_term() {
//Here what i'll do each certain time
}


ggwebphoto comments:

I understand what you're saying (and what the cronhook does), but am unsure how to execute the code. The events are sporadic (only once or twice/month). If I run this, I need to stop it, correct? Any thoughts on the custom fields? Or just use the same method. Appreciate the help.