Skip Navigation

[Resolved] Custom condition comparing a date with current timestamp

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to use a custom shortcode in a wpv-conditional shortcode test? It's not working.

Solution:
You need to register custom shortcodes (or custom functions) that you want to use in conditional expressions, at Toolset > Settings > Front-end Content.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/#checking-custom-shortcodes

This support ticket is created 6 years, 7 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by christianW-4 6 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#652523

I am trying to: Hide a link if a custom date field value is after today.

Link to a page where the issue can be seen: hidden link

I expected to see: a link for the first blocks at the bottom with the title "Drogen".

Instead, I got: nothing. The condition is always false.

The values are rendered correctly as can be seen on hidden link.
But the comparing does not what I expect it to do.

I use the following view template:

[cf_date_today]<br>
[types field='start-datum' output='raw']

[wpv-conditional if="( '[types field='start-datum' output='raw']' lt '[cf_date_today]')"]

and the following php code

function cf_date_today_func($atts) {
    $timestamp = strtotime('now');
    return $timestamp;
}
add_shortcode('cf_date_today', 'cf_date_today_func');
#652600

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Christian

If you use non-Toolset shortcodes in your conditions you must register them at Toolset > Settings > Front-end Content in the relevant section.

You shouldn't need to use a custom shortcode, though, you can use NOW() and other date-related values (https://toolset.com/documentation/user-guides/date-filters/) as described here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/#using-fields-together-with-date-filters

#652799

Thank you very much Nigel.
Works perfect.