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