Skip Navigation

[Resolved] Conditioal Shortcodes

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

Problem:
The issue here is that the user wanted to check if their custom field is empty using the conditional shortcode and display some content if it is.

Solution:

We have some documentation on how this can be done.
https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-types-checkboxes-field-for-non-empty-value

The above document will illustrate exactly how you can check if your field is empty

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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by Pete 3 years ago.

Assisted by: Shane.

Author
Posts
#2279811

Hi there,

We use Legacy for much of our sites, while on the rare occasion we use Blocks....the Conditional Block is very straight forward to use....and works great.

I saw a post on the forum that linked to this:
https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/#checking-types-checkboxes-field-for-non-empty-value

However I can't get my head round this.

This, part of one of our Legacy Grid Views...

<div class="col-sm-3"><span class='icon-style-1'><i class="fas fa-bed"><span class='number-style'>[types field='bedrooms' format='FIELD_VALUE'][/types]</span></span></div>

How and what would I need to wrap around this so it's hidden if the types field is left empty?

Thank you.

#2279911

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pete,

Thank you for getting in touch.

You can use the conditional below.

[wpv-conditional if="( '[types field='bedrooms' format='FIELD_VALUE'][/types]' ne ''  )"]

<div class="col-sm-3"><span class='icon-style-1'><i class="fas fa-bed"><span class='number-style'>[types field='bedrooms' format='FIELD_VALUE'][/types]</span></span></div>


[/wpv-conditional]

This will only display the section in the conditional if the bedroom field is not empty.

Please let me know if this helps.
Thanks,
Shane

#2280681

Hi Shane,

Long time no speak....hope all is well in your part of the world.

That worked GREAT! Thank you.

Final ask....using that code, or more the types field....is there a way to make the contents 'visible'?

Your previous hides the data perfectly however we need to replace it with something. The idea, to use an alternative code to display different contents using the same types filed.

Thanks again. Pete

#2280815

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pete,

I'm doing well 🙂 Hope you are as well.

Final ask....using that code, or more the types field....is there a way to make the contents 'visible'?

Your previous hides the data perfectly however we need to replace it with something. The idea, to use an alternative code to display different contents using the same types filed.

From this I gather that you want to display something if the field is empty correct? Rather than removing the information entirely. In this case you can simply check if the field is empty and then display your items.

Here is an example below.

[wpv-conditional if="( '[types field='bedrooms' format='FIELD_VALUE'][/types]' eq ''  )"]
 
Some Content goes here.
 
[/wpv-conditional]

Please let me know if this helps.
Thanks,
Shane

#2280879

Hi Shane,

Thanks very much for this. I see now with the code it the ' eq '' )"] for display and ne '' )"] to hide with certain types fields indicated.

Tried it and all works great. I didn't think Legacy would have codes and conditional would just be for Blocks.

Toolset saves the day again 🙂

Thanks very much for your help once again. Pete

#2280893

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pete,

No problem happy I was able to assist.

Yes our legacy mode does have conditionals and other various elements that can be used.

Most features in Blocks were built upon the legacy features or replaced with a simplified UI, for e.g the conditional block vs writing out the conditional shortcode manually.

If there are no further questions you can go ahead and mark this ticket as resolved.

Thanks,
Shane

#2280897

My issue is resolved now. Thank you!