This thread is resolved. Here is a description of the problem and solution.
Problem:
How to set CRED different post expiration date for each CRED post created.
Solution:
You should add date field to your CRED form and then use date field value and assign it to CRED expiration and use CRED API hook 'cred_save_data'.
This support ticket is created 7 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
The CRED form editor has a section for setting an Automatic Expiration Date per form. But the expiration time is set in weeks and days. For example, you can set the advert to expire in 4 weeks and 2 days after the advert is published.
However I am creating a jobs page where jobs expire on a specific date - its a bit counter intuitive to ask my editors to figure out the exact amount of days/weeks. It would make more sense if they could input a date for the post to expire - i.e set a post to expire 23rd June 2016
For posts, it will give you the calendar to choose the date as you wanted.
=> Using Automatic Expiration on CRED forms
[Section: Post Expiration settings in the WordPress post editor]
If you want to give post expiration date while creating the post, you can use CRED hook: 'cred_save_data'
For example:
/* Setting custom expiration date = closing date */
$expiry_date = TIME_STAMP_OF_EXPIRATION_DATE;
update_post_meta($post_id, '_expiration-date', $expiry);
I hope above information will help you to resolve your issue.
I think what you're saying is once the post is created via CRED, the editor can then go into the dashboard find the post and manually set the expiration date?
That dosent really work for me as my editors will not be given access to the dashboard only a page with the CRED form embedded (see attached).
So...
I have a CRED form embedded in a page which editors are using to create a job post (see attached) I want them to be able to set an expiration date using a calendar in the CRED form. Would you be able to tell me the steps for doing this?
ahh - Ok. I thought you were familiar with CRED API. I would love to assist you to step by step. Let me explain you step wise:
1) How do I add a date field to my cred form?
=> You can add CRED generic date field to your CRED form to take post expiration date value. We are adding this field so that we can take post expiration date from user:
2) What is the date field value
=> The date field value will be the selected date value from above date field.
3) How do i assign it to CRED expiration
Now - edit your current theme's functions.php file.
Add following code to your functions.php file:
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']==999){
$expiry_date = $_POST['post_expiration_date']['timestamp'];
update_post_meta($post_id, '_expiration-date', $expiry_date );
}
}
1) I've added the date field to my cred form - have I done this correctly? (see screenshot)
2) Is there any other way of doing this without editing my functions.php file? - i would rather not touch something like that, as I don't have a proper dev environment set up yet
1) I've added the date field to my cred form - have I done this correctly? (see screenshot)
=> Yes - thats correct.
2) Is there any other way of doing this without editing my functions.php file? - i would rather not touch something like that, as I don't have a proper dev environment set up yet
=> I'm afraid that there is not other way. You need to add that CRED hook so that CRED hook function will be called and due to that you can able to save the post-expiration date value to the field.
Hi i've done the above and the expire functionality is not working. Our developer wants to know if we need to set up some sort of cron task to make this work?
1)
Could you please share CRED form URL where we can select post expiration date?
2)
*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
I checked your setup and I found that you are using outdated CRED and Access plugin version.
Could you please update all Toolset plugins to its latest official released version. You can download latest plugins from:
=> https://toolset.com/account/downloads/
Also, I've changed your CRED form's expiration field name to: " _cred_post_expiration_time"
Now, once you update all plugins to latest version, I hope expiration functionality will work. You dont need to add any other code to functions.php to assign expiration date.
1) See screenshot for code in the plugin- we are using a plugin as we are not allowed to modify the functions.php file. Is there something I need to change in there to match the changes you made to the field?
2) Sorry I don't understand what you mean - to run the test I created a job post, using the CRED form on the create/jobs url. The job title is "Created on 4/7/2016". There is a date field at the bottom of the create/jobs form, which i filled in and set to expire on the 5th and clicked submit. (see screenshot) if you go to the /internal-vacancies page you can see that the job is still there