Skip Navigation

[Resolved] Untick a custom field after period of time

This support ticket is created 5 years, 5 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 17 replies, has 2 voices.

Last updated by Christian Cox 5 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1279949

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

#1280397

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.

#1280539

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?

#1281069

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.

#1281083

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

#1281329
Screen Shot 2019-07-01 at 5.32.42 PM.png

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.

#1281387
Screen Shot 2019-07-02 at 11.56.44 am.png
Screen Shot 2019-07-02 at 11.56.35 am.png

Aah ok, have changed it to a radio button.

Would this be correct? (I got "wpcf-featured-listing" from phpMyAdmin)

#1281407
Screen Shot 2019-07-02 at 12.09.30 pm.png

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

#1282085

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 :

 'meta_value' => '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/

#1282573
Screen Shot 2019-07-03 at 3.02.18 pm.png
Screen Shot 2019-07-03 at 2.54.12 pm.png

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

#1282597
Screen Shot 2019-07-03 at 3.05.12 pm.png

Time info from phpinfo

#1282611
Screen Shot 2019-07-03 at 3.10.51 pm.png
Screen Shot 2019-07-03 at 3.10.38 pm.png
Screen Shot 2019-07-03 at 3.10.26 pm.png

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

#1282637

Ok, weird thing... every time I click 'update post' the expiry date changes...

#1282657
Screen Shot 2019-07-03 at 3.26.49 pm.png
Screen Shot 2019-07-03 at 3.27.14 pm.png

Changed the function, however it didn't remove them from being featured 🙁

#1283237

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.