Skip Navigation

[Resolved] Conditional Output in a Layout

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

Problem:

I want to display only one view on the layout depending on which Custom Field is set to 'Yes'.

Solution:

it is possible with Views shortcode [wpv-conditional], you can try to follow our document to setup the conditions according to your requirements.

Relevant Documentation:

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

This support ticket is created 5 years, 5 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.

Our next available supporter will start replying to tickets in about 1.77 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 7 replies, has 2 voices.

Last updated by geoffD 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1256259

Hello

I have layout for a CPT 'Person' and on that layout I have 4 different views

VIEW 1
VIEW 2
VIEW 3
VIEW 4

The Person has 4 custom fields:

CHILD
PET
CASH GIFT
POSSESSION

and only one of these fields will be set to 'Yes' ..the others will default to 'No'

What I want to achieve is to display only one view on the layout depending on which Custom Field is set to 'Yes'

So for example
If CHILD = 'Yes' then

VIEW 1 - Display
VIEW 2 - Do not display
VIEW 3 - Do not display
VIEW 4 - Do not display

and if PET = 'Yes' then:

VIEW 1 - Do not display
VIEW 2 - Display
VIEW 3 - Do not display
VIEW 4 - Do not display

etc... Hope this makes sense...

Best wishes

Geoff

#1256519

Dear Geoff,

I think it is possible with Views shortcode [wpv-conditional], you can try to follow our document to setup the conditions according to your requirements:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

If you need assistance for it, please provide a test site with the same problem, fill below private message box with login details, also point out the problem page URLs, I can setup a demo for you. thanks

#1257461
Conditional Person.jpg

Hi Luo

The conditional output only works with each list inside the view, I need to only display one view template out of four depending on field data in the current post...I have attached a diagram to help explain. The diagram shows 4 page scenarios with 4 different CPT 'People'. Each page displays a different person and each person has some custom fields switched to either 'Yes' or 'No'.. There are also 4 different views on the template page and only one can be visible depending on the custom fields of the current page post...

Please can you tell me how to achieve this...many thanks

Best wishes
Geoff

#1257729

The [wpv-conditional] shortcode works in single "Person" post too.

You can use it to setup complicated conditions on custom fields., see our document:
Checking Types Fields and Custom Fields
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-types-fields-and-custom-fields/

#1257919

Hi Luo

I've looked at all the help guides and can't find a way to do it which is why I really need your help!

As pointed out in the diagram I need to view or hide an entire view within a layout based on the fields of the person on the page...

Best wishes
Geoff

#1257947

As I mentioned above, I can setup a demo for you.
https://toolset.com/forums/topic/conditional-output-in-a-layout/#post-1256519

Or you can provide your website database dump file in below private message box, I can test it in my localhost, thanks

Don't forget to point out the problem page URL

#1258995
Conditional-output.JPG

Thanks for the details, I can log into your website.

I assume we are talking about the layout "Layout For People":
hidden link

You can add a visual editor cell, click the "Conditional output" button, and setup the wpv-conditional shortcode, like this:

[wpv-conditional if="( $(child) eq 'Yes' )"]
VIEW NUMBER 1
[/wpv-conditional]

See screenshot Conditional-output.JPG, I have setup a demo in row 5, for your reference.

Please let me know if you need assistance to setup other shortcodes.

#1261545

My issue is resolved now. Thank you!