Skip Navigation

[Resolved] Add Post Expiration settings in the front end form

This support ticket is created 4 years, 10 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by rezas-2 4 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1654487

Hi Toolset team,

I need your help to add Post Expiration settings in the frontend form.
So I want my editor input content then set the post expired from frontend form.
Is it possible?

Thanks

#1654601

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Rezas,

Thank you for getting in touch.

If you have a frontend datepicker on your form you should be able to use the hook below to set this.

add_action('cred_save_data', 'set_expiration_date',10,2);
function set_expiration_date($post_id, $form_data)
{
    $forms = array( 35927 );
    if (in_array($form_data['id'], $forms)) {
  
        // update post publish date based on generic date field
        $timestamp = $_POST['wpcf-user-note-expiration-date']['datepicker'];
        $date = date('Y-m-d H:i:s', $timestamp);
        if(isset($timestamp)){
            $args = array(
                'ID' => $post_id,
            );
            wp_update_post( $args );
            // update post expiration date based on generic date field and time calculation
            $expiry_timestamp = $timestamp + ( 6 * 60 * 60 );
            update_post_meta($post_id, '_cred_post_expiration_time', $expiry_timestamp );
        }
    }
}

What you will need to do is to change the '35927' to the ID of your form and change 'wpcf-user-note-expiration-date' to the slug of your date field inclusive of the wpcf- prefix.

You can add this custom code in Toolset -> Settings -> Custom code and activate it.

Please let me know if this helps.

Thanks,
Shane

#1654803

My issue is resolved now. Thank you!