Skip Navigation

[Resolved] Display content conditionally to a URL field

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

Problem:
We want to display content conditionally depending on wether a certain URL field on our site (it's a term field) is populated or not.

Solution:
You can do this witt HTML conditinal.
The important part when working with URL fields is to return the raw value of the field instead of the formatted one, in HTML conditionals, like so:

[wpv-conditional if="( '[types termmeta='your_field' output='raw'][/types]' ne '' )" debug="true"]YES; URL IS SET[/wpv-conditional]

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

This support ticket is created 4 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 2 replies, has 2 voices.

Last updated by romanB-3 4 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#1581429

Hi,

[types termmeta="site-officiel-auteur"][/types]

This shows an URL registered as custom term field.

[wpv-conditional if="( is_tax('auteur', null) ne '0' )"]
    	[wpv-conditional if="( '[types termmeta='site-officiel-auteur'][/types]' ne '' )"]<p class="">SITE : [types termmeta="site-officiel-auteur"][/types]</p>[/wpv-conditional]
    	[wpv-conditional if="( '[types termmeta='site-officiel-auteur'][/types]' eq '' )"]<p class="">SITE VIDE ! [types termmeta="site-officiel-auteur"][/types]</p>[/wpv-conditional]
    [/wpv-conditional]

This doesn't display anything. Nor SITE nor SITE VIDE !!
Why would that be ?
Thank you.

#1581957

Taxonomy Archives loop over Posts, not over terms, this is a common misconception that leads to the belief that a Term Field should then display in a Taxonomy Archive for each term, but it doesn't, it will display for each Post with that term.

That is important to keep in mind.

Other than that I think you can just add "output='raw'" to the ShortCode like so to make it work:

[wpv-conditional if="( '[types termmeta='your_field' output='raw'][/types]' ne '' )" debug="true"]YES; URL IS SET[/wpv-conditional]
#1582071

In deed that worked! Thank you very much.
Nevertheless, a loop over terms would be great too !
My issue is resolved now. Thank you!