Skip Navigation

[Resolved] Expire by date

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'.

You can find proposed solution with the following reply:
https://toolset.com/forums/topic/expire-by-date/#post-406680

Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-api/#csd

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 23 replies, has 2 voices.

Last updated by stewartE 7 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#405740

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

Is this possible?

#405750

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The weeks and days you can use to configure the CRED form expiration.
=> https://toolset.com/documentation/user-guides/automatic-post-expiration/
[Section: Using Automatic Expiration on CRED forms]

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.

#406537
cred-form.PNG

Hi Sorry - I'm not sure I understand

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?

Thanks

#406544

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You should add date field to your CRED form and then use date field value and assign it to CRED expiration.

You can use CRED API: 'cred_save_data'
https://toolset.com/documentation/user-guides/cred-api/#csd

OR

'cred_before_save_data' hook:
https://toolset.com/documentation/user-guides/cred-api/#cbsd

For example:
/* Setting custom expiration date = closing date */
$expiry_date = TIME_STAMP_OF_EXPIRATION_DATE;
update_post_meta($post_id, '_expiration-date', $expiry);

#406653

I'm sorry I'm really not understanding your explanation at all. I don't really know what any of these steps mean or what i should do.

Can you break it down for me please.

1) How do I add a date field to my cred form?
2) What is the date field value
3) How do i assign it to CRED expiration

Thanks

#406680

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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:

For example:

[cred_generic_field field="post_expiration_date" type="date" class=""]
{
"required":0,
"validate_format":0,
"persist":0,
"default":""
}
[/cred_generic_field]

More info on generic field:
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

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 );
	}
}

where:
Replace '999' with original CRED form ID.

More info: CRED API: 'cred_save_data'
https://toolset.com/documentation/user-guides/cred-api/#csd

This is all you need to do. I hope above information will help you to resolve your issue.

#406721
date-field.PNG

Hi Minesh - thanks for explaining this for me 🙂

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

Thanks again!

#406732

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#411464

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?

Thanks

#411717

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#413020

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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"

 [cred_generic_field field="_cred_post_expiration_time" type="date" class=""]
{
"required":0,
"validate_format":0,
"persist":0,
"default":""
}
[/cred_generic_field]

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.

#413245

Hi ~Minesh - I ran a test overnight and unfortunately that still hasn't worked.

You mentioned you changed the form's expiration field name to: " _cred_post_expiration_time would i need to change that in my plugin as well?

#413275

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Where in your plugin?

The CRED form has post expiration time field and you just need to save it.

#413332
plugin.PNG
datefield.PNG

Hi

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

So what do I need to save?

Thanks

#413369

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I understand you want to remove the posts from the job view which are expired - correct?

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.