Skip Navigation

[Resolved] Conditonal statements lead to redirect

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2242939

I have this piece of code running successfully in a view so that if it is NOT between the 2 times entered currently, it will redirect to another page. However, the redirect is not instant. My conditional statement in the view is:

[wpv-conditional if="( $(wpcf-publish-note-date) lte '[get_current_timestamp]' ) AND ( $(wpcf-unpublish-note-date) gte '[get_current_timestamp]' ) " evaluate="false"]
[redirect url='/notes?church=central' sec='0']
[/wpv-conditional]

However even with the shortcode in there for redirecting set to 0, the original post still shows for a second on the page, before redirecting. I need to avoid that. So how do I set that conditional statement to redirect to a page without a delay?

#2243251

Hello,

There isn't such kind of built-in feature within Toolset plugins, it needs custom codes, for example, you can use WordPress built-in action hook "template_redirect" to trigger a PHP function:
https://developer.wordpress.org/reference/hooks/template_redirect/

In this PHP function, check if it is your single custom post:
https://developer.wordpress.org/reference/functions/is_singular/
Get the those two custom date field values:
https://developer.wordpress.org/reference/functions/get_post_meta/
Compare them with current timestamp
https://developer.wordpress.org/reference/functions/current_time/
Then redirect to other URLs:
hidden link