Skip Navigation

[Resolved] _cred_post_expiration_time not working

This thread is resolved. Here is a description of the problem and solution.

Problem:

Update _cred_post_expiration_time field with action hook cred_save_data.

Solution:

You can use a high priority value in action cred_save_data hook, for example:

https://toolset.com/forums/topic/_cred_post_expiration_time-not-working/#post-1285885

Relevant Documentation:

https://developer.wordpress.org/reference/functions/add_action/

This support ticket is created 5 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by Armando 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1285577

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!

#1285885

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

#1289177

Thanks! It worked before with the current set up. I appreciate your help!