Skip Navigation

[Gelöst] Make a property "new" for fixed time

This support ticket is created vor 8 Jahre. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 4 Antworten, has 2 Stimmen.

Last updated by zoeS vor 8 Jahre.

Assisted by: Luo Yang.

Author
Artikel
#380512

Hi, I'm using the real estate reference site. My client would like to be able to mark properties as "new" , and for that marker to remain for a fixed time, but the tricky thing is that it should not be based on the date the post was created, or even last edited. The expiry date of the "new" status should be based on when the status was added. This is so that for example, if the price is dropped, the property rises to the top, but only for a couple of months. Is this doable? Many thanks

#380776

Dear zoe,

I suggest you create a custom field group with two fields:
1) A custom checkbox field "New status"
2) A custom date field "Expired time"
When you update the property post as "price is dropped", update the field "New status" as checked, and setup the field "Expired time" as what you want.
Then setup the view with filters:
1) "New status" is checked
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
2) TODAY() > the field value of "Expired time":
https://toolset.com/documentation/user-guides/date-filters/

#380852

Thank you Luoy, that sounds like it would work, do you think there is any possible way of them not having to enter an expiry date? Can the expiry field be automatically populated with the current date (+ 14 days for example) at the time that the "new" box is checked? I suppose even if that was possible, it would cause the date to be reset any time the property was edited.

#381118

Yes, you can try with CRED action hook "cred_save_data", check if the custom "new" field is checked, then update the date field "Expired time" as current date (+ 14 days), and Types date field is storing time stamp value, for example:

add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form and wpcf-new has value
    if ($form_data['id']==123 && get_post_meta($post_id, 'wpcf-new', true) != '')
    {
		//update expired-time to current date (+ 14 days)
           update_post_meta($post_id, 'wpcf-expired-time', time()+14*24*60*60); 
    }
}

Please replace "wpcf-new" with the custom field slug of the custom "new" field,
replace "wpcf-expired-time" with the custom field slug of the custom "Expired time" field
replace 123 with your CRED form ID.

More help:
hidden link
https://toolset.com/documentation/user-guides/cred-api/#csd

#381385

Brilliant, thank you!

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