Skip Navigation

[Resolved] Hide Parent View if nested Child has No Posts – WordPress Archives

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

Problem:

In the nested view, I have created an Archive Page for "Job-Type" and I am trying to list all the "Services" that have the current page "Job Type" selected, nested in a Parent/Child view by "Service Category", I want to display term's title only when there is items in child view.

Solution:

In your case, you can pass a shortcode attribute to the child post view, in the child view, use shortcode [wpv-attribute] to get the attribute value.

For example, in the parent taxonomy view, in section "Loop Editor", find and edit the child post view's shortcode, pass term's title as shortcode attribute, like this:

[wpv-view name="CHILD-VIEW-SLUG" term_title="[wpv-taxonomy-title]"]

Edit the child post view, in section "Loop Editor", after shortcode [wpv-items-found], display above attribute value, like this:

[wpv-attribute name="term_title"]

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute

This support ticket is created 6 years, 1 month 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 – 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 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1151375

I have a custom post type of "Services" on my website, with two taxonomies: 1) "Job Type"; and 2) "Service Category". The "Services" CPT contains a list of all the services our company provides, and the taxonomies of "Job Type" and "Service Category" help organize the posts.

I have created an Archive Page for "Job-Type" and I am trying to list all the "Services" that have the current page "Job Type" selected, nested in a Parent/Child view by "Service Category". So like, this

Job Type Archive Title: Commercial

<div> [Service Category: Roofing]
-- Roofing Service #1 (Service CPT)
-- Roofing Service #2 (Service CPT)
-- Roofing Service #3 (Service CPT)
</div>

<div>
[Service Category: Insulation]
-- Insulation Service #1 (Service CPT)
-- Insulation Service #2 (Service CPT)
-- Insulation Service #3 (Service CPT)
</div>

Example: hidden link

The idea is that only "Services" that match the current page "Job Type" and "Service Category" will display. Everything is working properly EXCEPT "Service Categories" with no matching "Services" still show up. I've tried using every filter available, tick the "Do Not Show Empty Items" boxes, etc., but I cannot figure out how to hide the <div> sections that don't have posts the match the filter. I even tried to get crazy and use CSS to hide the blocks (I added a class based on slug), but I cannot get an array within the [wpv-no-items-found] shortcode because it's outside the loop.

Should I be using a CPT relationship instead of two (2) taxonomies? Would love some help!

#1151720

Hi,

In your case, you can pass a shortcode attribute to the child post view, in the child view, use shortcode [wpv-attribute] to get the attribute value.

For example, in the parent taxonomy view, in section "Loop Editor", find and edit the child post view's shortcode, pass term's title as shortcode attribute, like this:
[wpv-view name="CHILD-VIEW-SLUG" term_title="[wpv-taxonomy-title]"]

Edit the child post view, in section "Loop Editor", after shortcode [wpv-items-found], display above attribute value, like this:
[wpv-attribute name="term_title"]

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute
This shortcode displays the value of an attribute in a View shortcode.

#1152432

My issue is resolved now. Thank you!

#1152788

You are welcome