Saltar navegación

[Resuelto] Custom condition comparing a date with current timestamp

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 8 meses. 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)

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por christianW-4 hace 6 años, 8 meses.

Asistido por: Nigel.

Autor
Mensajes
#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: enlace oculto

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 enlace oculto.
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

Idiomas: Inglés (English ) Español (Español )

Zona horaria: 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.