Home › Toolset Professional Support › [Resolved] Post expiry date
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)
This topic contains 22 replies, has 3 voices.
Last updated by leilaG 2 years, 6 months ago.
Assisted by: Shane.
Hello,
We have a jobs section with posts that have an expiry date.
When the expiry date has passed, the post are not being deleted, and the date changes to 01/01/1970.
Hello. Thank you for contacting the Toolset support.
Can you please share screenshot of your form edit page so I can see how you setup your post expiration settings?
Hi, Code being used and screen shot attached of settings.
[cred_generic_field type='date' field='expiration-date']
{
"required":1,
"validate_format":0,
"default":""
}
[/cred_generic_field]
add_action('cred_save_data', 'func_set_custom_post_expiration_date_time',10,2);
function func_set_custom_post_expiration_date_time($post_id, $form_data){
// if a specific form
if ($form_data['id']==4896){
$expiry_date = $_POST['expiration-date']['timestamp'];
update_post_meta($post_id, '_cred_post_expiration_time', $expiry_date );
}
}
Thank you!
I see from your screenshot you shared that you did not setup the "Post expiration" setting on your form: "Set expiration date for post created or edited by this form".
Can you please set the post expiration setting to "Trash" as you want to delete the post.
=> https://toolset.com/course-lesson/setting-up-automatic-post-expiration/#enabling-automatic-expiration-of-posts
Then, try to create a new post and check if that works as expected.
Hey Minesh,
We was instructed to unticked that setting from this ticket - https://toolset.com/forums/topic/form-post-expiration-date/#post-2292815
Hi Leila,
Here in the post you mentioned that this was working.
https://toolset.com/forums/topic/form-post-expiration-date/#post-2292841
Given that this is based on custom code then the debugging ability we have here is quite limited as this is outside of the realm of what is possible by the plugin by default.
Can you explain if it actually worked when Waqar had provided the solution and if it did what changed that caused it to stop working.
Thanks,
Shane
The thing is that post expiration setting that if post expires what to do is set using the setting "Set expiration date for post created or edited by this form" on your post form. As you can see with the following Doc:
=> https://toolset.com/course-lesson/setting-up-automatic-post-expiration/#enabling-automatic-expiration-of-posts
Now, what I suggest what if you try to set above post expiration setting and set the post to be "Trash" if post is expired and then create a new post for testing purpose and see if that works as expected. If not, whats not working as expected we will require to review that.
Thanks for the instructions, I set to 'Trash' and tested but it's not taking the date the user fills out in the form. Its changing to the setting: Post will expire in 4 Weeks after this form is submitted.
Can you please share problem URL where you added your form as well as admin access details. Let me check whats going wrong with your setup.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I just checked with my local test installation where I imported the Toolset form and post type Job as well as associated custom fields.
When I checked on my local test install it just works fine. I set the yesterday's date that is 24th March as post expiration date and I've set the post expiration settings from Toolset Form to be post expired after 1 minute after we submit the post and I've also changed that CRON should be run every one minute by adding the following code:
add_filter ('cred_post_expiration_cron_schedules', 'func_cron_one_minute_schedule', 10,1); function func_cron_one_minute_schedule ($schedules) { $schedules['every1minute'] = array( 'interval' => 1 * MINUTE_IN_SECONDS, 'display' => __( 'Every 1 minute' ) ); return $schedules; }
And I've set this cron schedule so that CRON should run every minute from: Toolset => Settings => Forms => Other section.
I can see its working as expected.
But when I try to create the post using the form, I've created the post with title "first" using the form but it seems on your site the CRON should be blocked or not working as expected.
=> hidden link
You can see the post with title "first" post stays as it is.
Can you please test on some other server where there should be no restrictions or blocking or even try to check on localhost or other server.
Hey Minesh, I tested it again by adding a job on the form - hidden link
with expiry date of 29/03/22 - hidden link
But the post did not get removed on its expiry date - hidden link
Thanks
That is why I shared with my previous reply.
But when I try to create the post using the form, I've created the post with title "first" using the form but it seems on your site the CRON should be blocked or not working as expected.
=> hidden link
You can see the post with title "first" post stays as it is.
The post is not removed. Can you please check if CRON is allowed on your server as it seems the CRON is not fired as expected in this case.
Hi, I checked with WPengine, they turned on the server Cron and confirmed Cron is working for the staging site. I retested adding a job with expiry date 01/04/22 but the job still remained on the list - hidden link
It does not seem that CRON us running on your site as I created a post and it stays there.
Either you have to test on server where there will be no CRON restriction or you can share with me another server where you are sure that CRON is running or alternatively I can share a demo site source which you will have to install on your server and if that does not work that means CRON is not running on your server.
Okay, we can test on the live site.