Hi,
I have created a custom post type with bunch of fields (10 fields including a date and text field). Now I need to show one text field based on a condition (date field gt Now()). I have created a elementor single page template for this post.
I am able to put all fields and create a custom template page but not able to find a way to show this particular text field based on date field condition.
Kindly help me on this.
Regards,
Lokesh
Hi, the only way I'm aware of to use conditionals with Elementor is to use Toolset's conditional HTML in a text element. Here's an example of a conditional testing a custom field value against the current timestamp NOW():
[wpv-conditional if="( $(wpcf-book-date-1) gt NOW() )"]
This book's date field is later than NOW.
[/wpv-conditional]
We have more information about conditional HTML in our documentation here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
Thanks for the quick revert. Where do I need to place this code? I mean which Elementor widget?
[wpv-conditional if="( $(wpcf-book-date-1) gt NOW() )"]
This book's date field is later than NOW.
[/wpv-conditional]
I have a text field by name -> Speaker so how do you put that field in conditional statement?
[wpv-conditional if="( $(wpcf-book-date-1) gt NOW() )"]
[/wpv-conditional]
Where do I need to place this code? I mean which Elementor widget?
Use a Text widget.
I have a text field by name -> Speaker so how do you put that field in conditional statement?
Use the field slug with a wpcf- prefix, like this:
[wpv-conditional if="( $(wpcf-speaker) eq 'Lokesh Gupta' )"]
The speaker is Lokesh Gupta.
[/wpv-conditional]
If you create an unassigned Content Template, there is a button "conditional output" you can use to create these conditionals using a GUI. Then you can copy + paste this information into a text element in the Elementor builder.
Thanks again for the reply. I want a field with in conditional statement
[wpv-conditional if="( $(wpcf-book-date-1) gt NOW() )"]
$(wpcf-speaker)
[/wpv-conditional]
Do you think this will work?
No, the $(slug) syntax only works in the "if" part of the shortcode. To display a Types field inside the conditional, use the Types field shortcode without the wpcf- prefix:
[wpv-conditional if="( $(wpcf-book-date-1) gt NOW() )"]
[types field="speaker"][/types]
[/wpv-conditional]
We have more examples here:
https://toolset.com/documentation/customizing-sites-using-php/functions/#textfield
Click "+ More" to see more examples of each field type.