Problem: I have a Form that is used to create posts. I would like to schedule those posts for future publication, and I would like to set a custom post expiration date based on the future publication date. When the post expires, I would like to modify a custom field value.
Solution:
Add the following code to modify the publication date and post status:
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 ); } } }
Add this code to modify the custom field value when the post expires:
function my_custom_expire_actions($custom_actions, $post_id, $form_data) { $custom_actions[] = array( 'meta_key' => 'wpcf-membership-type', 'meta_value' => 'Charter' ); return $custom_actions; } add_filter('cred_post_expiration_custom_actions', 'my_custom_expire_actions', 10, 3);
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/user-guides/automatic-post-expiration/
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 |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 21 replies, has 2 voices.
Last updated by 6 years, 4 months ago.
Assisted by: Christian Cox.