Skip Navigation

[Resolved] Single template displays empty child post taxonomies

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

Problem: I have a View of terms in a custom taxonomy. Nested in the Loop of that View I have placed another View of posts, filtered by taxonomy term. It's working as expected but I would like to hide the taxonomy term from the outer loop if no posts are found in the inner loop.

Solution: Move the taxonomy term shortcode from the Loop of the term View into the wpv-items-found section of the post View. Do not place it in the Loop of the post View, since it may be repeated there.

This support ticket is created 6 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Rich Strauss 6 years ago.

Assisted by: Christian Cox.

Author
Posts
#1197062

Hi there,

I have two related custom post types:

1. Programmes (Parent Post)
2. Sessions (Child Post) >> Session Modules (Taxonomy)

Relationship: programme_session — Migrated >> Programmes [0 .. 1] << Sessions [*]

The relationship was migrated from the old Toolset, and on the ‘Edit relationship’ screen it says:

Programmes: 1 Programme can be assigned to one Session
Sessions: Infinite Sessions can be assigned to one Programme

- Each Programme is one year, for example ‘Way of the Heart 2016’
- Session Modules are the months in that year, for example ‘January 2016’, ‘February 2016’ etc
- Each Session Module has a few Sessions (Webcasts) assigned.

======================

Here’s my problem, and with the Programmes single template:

I want to display all the Session Modules, with the nested Sessions belonging to each Session Module.

As you can see, it’s working >> hidden link

But, the empty Session Modules, that does not have any Sessions assigned to this Programme, are also showing, for ex:

January 2017- No items found
February 2017 - No items found
Etc

(I’m not sure if I set this up right, perhaps Session Modules should be a CPT, and NOT a taxonomy?)

In any case, the below is what I have to display the current Programmes single template:

======================

Single Template: Programmes Single >>
[wpv-view name="programme-modules" orderby="id" order="asc"]

======================

View: Programme Modules
Terms of the taxonomy Session Modules ordered by , ascending

<wpv-loop>
<h2>[wpv-taxonomy-link]</h2>
[wpv-view name="module-sessions-by-module-per-programme"]
</wpv-loop>

======================

View: Module Sessions by Module per Programme
Sessions ordered by post date, ascending

Has two filters:

1. Filter by post relationship or repeatable fields group owner
Select posts in a programme_session relationship that are related to the Post where this View is shown.

2. Taxonomy filter
Select posts with taxonomy:
Session Modules set by the parent Taxonomy View

And the template

<wpv-loop>
[wpv-post-body view_template="loop-item-in-module-sessions-by-module-per-programme"]
</wpv-loop>

Templates for this view:
Loop item in Module Sessions by Module per Programme
[wpv-post-link]<br/>

======================

Can you please advise me in displaying the single Programmes template without the empty Session Modules?

And can you please advise me on whether the Session Modules would play better as CPT’s instead of a taxonomy?

Thank you so much!

Rich

#1197556

Hi, one approach here is to move the taxonomy link into the View of Module Sessions. So instead of this:

<wpv-loop>
<h2>[wpv-taxonomy-link]</h2>
[wpv-view name="module-sessions-by-module-per-programme"]
</wpv-loop>

You cut out that entire h2 tag. Paste it into the "module-sessions-by-module-per-programme" View's Loop editor anywhere inside the wpv-items-found section, but outside the wpv-loop tags. Now the taxonomy link will only be displayed if there are results in the View.

<h2>[wpv-taxonomy-link]</h2>
<wpv-loop>
[wpv-post-body view_template="loop-item-in-module-sessions-by-module-per-programme"]
</wpv-loop>
#1197745

Brilliant, thank you Christian!

That removed the titles, but I was leftover with the 'No items found' lines, so I just commented it out in the 'module-sessions-by-module-per-programme' view's Loop Editor:

[wpv-no-items-found]
<!--[wpml-string context="wpv-views"]No items found[/wpml-string]-->
[/wpv-no-items-found]

Thanks again, well seen!