Tell us what you are trying to do? We have ads that can be paid to be 'featured'. This is currently manually handled by ticking a "featured listings" box, which sticks the post to the top of the page. I would like to be able to set a time of 14 days, and once that time is up, the featured listings box is UNticked.
Is there any documentation that you are following? Lots of googling...
Is there a similar example that we can see?
What is the link to your site? hidden link
Hi, sorry there was a problem with your chat ticket so I had to convert this to a standard forum ticket.
I would like to be able to set a time of 14 days, and once that time is up, the featured listings box is UNticked.
If the post is created using Forms, you can use post expiration to trigger a custom action that modifies some custom field value. We have more information about that here: https://toolset.com/documentation/user-guides/automatic-post-expiration/#what-happens-when-posts-expire
I'm available to assist with that code if you need help.
If the post is created in wp-admin, then there is no Toolset-based expiration system that will handle the 14-day timeout event. That would require custom code that falls outside the realm of Toolset, unfortunately.
Hi Christian,
The posts are created with the Toolset Forms, and I tried to set it up so that you could feature an existing post, however when I tried to set the post expire to 14 days, it said it was expired 10 hours ago.
Do I have to have the featured post as a NEW post to include the post expire?
Sure, you can modify the expiration date of an existing post in an Edit Post Form. The expiration date calculation is based on the publish date, though, not the current date. What you saw may be an indication that the post was originally published around two weeks ago, and the expiration time frame has already elapsed. If that doesn't seem to be the case here, I can take a closer look.
It was doing it on posts I had just made - working on a staging site. I would make a post, a couple of minutes later upgrade it to featured, and it instantly said time expired '10 hours ago' - but it was showing as featured.
I don't mind if the user has to create a new post for a featured spot if the expiration date is based of published date (which I worked out that it was), but is there a way to set it so that after the 14 days have passed, it unticks the featured checkbox and shows as a regular post?
I tried the code in the link you shared, however it wasn't seeming to untick it after time had passed (had it set to a couple of minutes for testing purposes).
The expiration API offers a way to change a field value, so instead of using a checkbox I would consider using a radio button. The radio should have two options: Not Featured (1) or Featured (2). You can make "Not Featured" the default option (see the attachment here). Then in the API hook you could change the field value to be 1 when the expiration event fires.
Aah ok, have changed it to a radio button.
Would this be correct? (I got "wpcf-featured-listing" from phpMyAdmin)
Just tested it with the code above, and it says "10 hours ago" it expired 🙁
Have it set to 2 minutes expiry for testing purposes
Would this be correct? (I got "wpcf-featured-listing" from phpMyAdmin)
Instead of 'meta_value'=>'No' you should set the raw value of the custom field, which is 1 :
Just tested it with the code above, and it says "10 hours ago" it expired
Well the code isn't changing the expiration date so something else must be going on. Remove the code and test the expiration setting just to be sure, but my guess is it will behave the same way. There could be a timezone setting discrepancy, or there could be a bug. Another client reported a similar problem yesterday where the expiration date is set incorrectly, and we're still investigating that. Can you tell me your computer's timezone, the timezone setting and date/time formats in wp-admin > Settings > General, and your server timezone? The server timezone information can be found in a phpinfo page. We have information about creating one of those available here under "How to check the PHP version" https://toolset.com/toolset-requirements/
Took the code out - and yup, still said 10 hours ago on a brand new post.
Attached two images - one is the setting in WP, the other is from running a the following on the server:
<?php
echo "The time is " . date("h:i:sa");
?>
Time matches my current time
Ok, so some troubleshooting...
I added a new post, it said expired 10 hours ago.
I went into the post and manually changed the expiry time for 1 minute ahead of our current time (3rd July at 15:11)
When I updated the post however, it changed the expiry date to 4th July 01:11) - but showed it was expiring in 1 minute...
Ok, weird thing... every time I click 'update post' the expiry date changes...
Changed the function, however it didn't remove them from being featured 🙁
Okay thank you for the extra information. The support team is now reasonably confident there is an issue with post expiration dates that was not resolved in the latest release, which was supposed to fix some issues with expiration dates. I'm reporting your case as well as another case where the problem can be seen, and hope to have some feedback for you soon. For now, it appears that expiration dates are not being saved or displayed correctly in some non-UTC WP timezone settings. I'll let you know as soon as I have some additional information to share about that.