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]

Shane
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
America/Jamaica (GMT-05:00)
Hi Mike,
Thank you for getting in touch.
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.
[wpv-conditional if="( $(wpcf-publish-note-date) lte 'time()' ) AND ( $(wpcf-unpublish-note-date) lte 'time()' )"]
Please let me know if this helps.
Thanks,
Shane
Thanks for the help. Unfortunately it still isn't working.
I did add time to functions: lien caché
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.

Shane
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
America/Jamaica (GMT-05:00)
Hi Mike,
Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?
Please where applicable please provide me with a link to an example page where I can see the issue.
I've enabled the private fields for your next response.
Thanks,
Shane

Shane
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
America/Jamaica (GMT-05:00)
Hi Mike,
Thank you for the credentials.
However i'm getting an unknown email error when trying to log in.
Can you check on this one for me.
Thanks,
Shane
Try test111@test.com as email to login with. Does that help?

Shane
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
America/Jamaica (GMT-05:00)
Hi Mike,
This should now be working.
What I did was to wrap the time() function in a shortcode and use the shortcode in the conditional instead.
function get_current_timestamp() {
return time();
}
add_shortcode( 'get_current_timestamp', 'get_current_timestamp' );
Please let me know if this helps.
Thanks,
Shane
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?
Thanks for your help!

Shane
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
America/Jamaica (GMT-05:00)
Hi Mike,
The issue should now be resolved.
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.
Thanks,
Shane
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.

Shane
Supporter
Les langues:
Anglais (English )
Fuseau horaire:
America/Jamaica (GMT-05:00)
Hi Mike,
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.
Thanks,
Shane
My issue is resolved now. Thank you!