Skip Navigation

[Resolved] Conditonal statements between 2 times

This support ticket is created 3 years, 1 month 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 13 replies, has 2 voices.

Last updated by mikeH-3 3 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#2239909

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]

#2239919

Shane
Supporter

Languages: English (English )

Timezone: 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

#2239975

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.

#2240035

Shane
Supporter

Languages: English (English )

Timezone: 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

#2240037

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

private fields

#2240171

Shane
Supporter

Languages: English (English )

Timezone: 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

#2240175

Try test111@test.com as email to login with. Does that help?

#2240711

Shane
Supporter

Languages: English (English )

Timezone: 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

#2240927

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!

#2241017

Shane
Supporter

Languages: English (English )

Timezone: 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

#2241077

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?

#2241175

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.

#2241645

Shane
Supporter

Languages: English (English )

Timezone: 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

#2241721

My issue is resolved now. Thank you!