I am trying to:
Set expire time base don selection from field
I expected to see:
Expire time set correctly
Instead, I got:
Default expire time
Hello, I had this working on another site of which I am currently re-designing.
I am trying to set the post expire date based on user selection (woo-commerce product). I have a radio button the user selects (30 days or 90 days). I have the following:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data){
// if a specific form
if ($form_data['id']==6407){
//get the value from the field as it appears in the post with the ID from above and assign it to a variable
$product_id = get_post_meta($post_id, 'wpcf-post-length-job', true);
if($product_id == 664){
$timestamp = current_time('timestamp') + 30 * DAY_IN_SECONDS;
}else if($product_id == 665){
$timestamp = current_time('timestamp') + 90 * DAY_IN_SECONDS;
}
update_post_meta($post_id, '_cred_post_expiration_time', $timestamp);
}
}
I have confirmed that the product if statement works. I have confirmed the return of the UNIX time stamp values are correct (30 days and 90 days). So everything works correctly until it gets to:
update_post_meta($post_id, '_cred_post_expiration_time', $timestamp);
Please advise why the post expiration is not being updated for the current values set in $timestamp.
Thanks!
Hello,
Please try to modify this line of your PHP codes from:
add_action('cred_save_data', 'my_save_data_action',10,2);
To:
add_action('cred_save_data', 'my_save_data_action',999,2);
And test again.
More help:
https://developer.wordpress.org/reference/functions/add_action/
$priority
(int) (Optional) Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
Default value: 10
Thanks! It worked before with the current set up. I appreciate your help!