Skip Navigation

[Résolu] Need help with conditional display when there are 3 possible states

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 2.58 hours from now. Thank you for your understanding.

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

Last updated by webD-3 Il y a 4 années et 11 mois.

Assigned support staff: Minesh.


I am working in Layouts for a "Page."

I have a custom post type "Brochures" defined in Types which is associated with Pages.

For most pages, all the brochures belong to the same category, but in one instance there are two separate categories of brochures that must be displayed and in a couple additional instances there are no brochures at all.

The desired result - pages with a single category of brochures display those brochures. The page with two categories of brochures display those brochures in two separate category-specific lists. And pages with no brochures omit the display entirely.

I have set up three separate Views.

One, "Brochures View", is set to display all brochures that are children of the Page. This is sufficient for all but the one exception page.

The 2nd and 3rd views are set to display the brochures that match the specific categories that need to be displayed on the exception page.

I then have a Custom Field "Product Information" (custom field associated with Pages) that is empty except on the exception page, where it contains the shortcodes from the 2nd and 3rd views so that those two categories can be shown together.

I'm having trouble getting the wpv-conditional code structured properly so that I get the desired result on all pages.

It is line 6 below that is giving me trouble. If I remove line 6, everything is fine except that pages with no brochures show "No items found" instead of displaying nothing at all, which is the desired result. I have tried testing for the Brochures View being empty, and tried testing for individual fields in the Brochures post type being empty, but nothing seems to work. I have also tried making this conditional the outermost conditional, testing for presence of brochures first and then nesting the test for wpcf-product-information inside this, but that doesn't seem to work either.

[wpv-conditional if="( $(wpcf-product-information) eq '' )" evaluate="false"]
<h3><i class="fa fa-files-o"></i> Product Brochures</h3>
[types field='product-information'][/types]
[wpv-conditional if="( $(wpcf-product-information) eq '' )" evaluate="true"]
  [wpv-conditional if="( NOT(empty($(wpcf-brochure-name))) )"]
  <h3><i class="fa fa-files-o"></i> Product Brochures</h3>
  [wpv-view name="brochures-view"]

Sorry for a long post that likely is not super clear. If I need to approach this differently please help me get pointed in the right direction. Thank you.


In reading my post after submitting, there is an empty line in the code, so what I describe as Line 6 is the 6th actual line of code, or the line labeled as Line 7.



Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

If you just do not want to display "No Items found" text what if you remove the "No Items found" from your view's loop output editor - Does this help?


Minesh, thank you for the reply.

Your comment helped me along to way to figuring this out.

I got rid of lines 6 and 10 entirely, to remove the nested conditional.

I then removed line 7 - the h3 heading - and moved it into the View, inside the wp-items-found portion of the loop, then removed the items-not-found portion.

Now I have achieved my desired result.

Ultimately the answer, from my perspective, is that testing for the presence of child posts has to happen in the View, not in the Layout.

I'm still learning Toolset and this is one more step towards understanding it better. Thank you for your assistance.