Problem: After two days have passed from the time of post creation, I would like to display some text on my post that says the post has expired.
Solution: Use two separate custom date fields to store the post creation timestamp and the post expiration timestamp. Use a custom function or custom shortcode to compare the expiration timestamp with the current timestamp. The following code example shows how to set the two requested custom field values:
//FECHA AUTOMÁTICA BONOS add_action( 'save_post', 'tssupp_auto_set_date_fields', 100, 3 ); function tssupp_auto_set_date_fields( $bonos, $post, $update ) { $post_type = 'bonos'; $created_field_slug = 'fecha-de-creacion-del-bono'; // edit your created field slug here $expiration_field_slug = 'fecha-de-caducidad'; // edit your expiration field slug here // do not edit below this line $created_field_value = get_post_meta($bonos, 'wpcf-' . $created_field_slug, true); $expiration_field_value = get_post_meta($bonos, 'wpcf-' . $expiration_field_slug, true); if ( $post->post_status == 'publish' && $post->post_type == $post_type && !$created_field_value ) { update_post_meta( $bonos, 'wpcf-' . $created_field_slug, date('U') ); } if ( $post->post_status == 'publish' && $post->post_type == $post_type && !$expiration_field_value ) { update_post_meta( $bonos, 'wpcf-' . $expiration_field_slug, (date('U') + 172800) ); } }
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.
Our next available supporter will start replying to tickets in about 8.73 hours from now. Thank you for your understanding.
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 18 replies, has 2 voices.
Last updated by 4 years ago.
Assisted by: Christian Cox.