Skip Navigation

[Résolu] How to display a field conditionally in a custom post using elementor plugin?

This support ticket is created Il y a 4 années et 10 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Marqué : 

This topic contains 5 réponses, has 2 voix.

Last updated by Christian Cox Il y a 4 années et 10 mois.

Assisted by: Christian Cox.

Auteur
Publications
#1241001

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

#1241010

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/

#1241014

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]

#1241020

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.

#1241022

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?

#1241023

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.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.