I have created a 'publish-note-date' custom field and an 'unpublish-note-date' field for posts. Both are date/time fields.
How do I write a proper if/then statement to check whether the current day/time is between these 2 different date/times that I entered for a post, and then if so, post a message? I tried this below, but it doesn't really work.
[wpv-conditional if="( $(wpcf-publish-note-date) gte 'NOW()' ) AND ( $(wpcf-unpublish-note-date) lte 'NOW()' )"]
between this given time
[/wpv-conditional]
[wpv-conditional if="( $(wpcf-publish-note-date) lte 'NOW()' ) AND ( $(wpcf-unpublish-note-date) lte 'NOW()' )"]
not between this given time
[/wpv-conditional]
You can use the time() built in php function to do this, however you must first register the function at Toolset -> Settings -> Frontend and under the Functions inside conditional evaluations.
Add the function name "time"
Then you'll be able to use it in the conditional statements like below.
Thanks for the help. Unfortunately it still isn't working.
I did add time to functions: hidden link
And I used this code:
[wpv-conditional if="( $(wpcf-publish-note-date) lte 'time()' ) AND ( $(wpcf-unpublish-note-date) lte 'time()' )"]
between current hours
[/wpv-conditional]
It is now 11:30am here and I have the post publish time set for 12 today and the post unpublish time set for 13 today. So technically, nothing should show since we are not between those 2 hours.
But "between current hours" does show right now, even though it is not between hour 12 and hour 13.
Basically I am setting a publish and unpublish date for each post. If a person comes to the site and goes to that post between those 2 times, it shows them a message there.
Thanks for taking a look. I'm a bit confused though as to what you did because it doesn't look like anything changed in terms of the script working. "Between current hours" is still showing at the top of the post even though that post has a start publish date/time of dec 8th 12pm and unpublish date/time of dec 8th 1pm. If it was working properly, nothing would show since we are currently NOT between those hours on that day. It should only be showing that piece of text if it's between those hours currently, on that day. Does that make sense?
The second problem was with the custom field name for the Unpublished note date. You had used the wrong slug. Correcting this and the conditional should be working as intended.
The message still shows though even though it's NOT between the 2 times I mentioned. Instead of 'between customer hours' i made it so it shows the actual times of the publish and unpublish fields so that it makes more sense.
You'll see it shows the message at the top of the post even though it isn't between those 2 times currently. Thoughts?
I had to use a different plugin to get this to work. If I need to use toolset for this kind of task again, I'll re-open the ticket so we can figure out how to get this to work. I was in a time crunch and couldn't wait anymore for the fix. I do appreciate the help.
I must apologize for not being able to assist in a timely fashion on this one, however i'm happy to see that you were able to arrive at a suitable solution for your scenario.
Please go ahead and mark this ticket as resolved when you're ready.