Skip Navigation

[Resolved] Hiding post/content without specific child post

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

Problem:
How to list parent posts (and their children) but omit parents that don't have any children?

Solution:
You need an outer View which returns all of the parent posts, which does not output any fields from the parent itself, and only contains the embedded View to return all of the child posts from each parent.

Then in the output of this embedded View you can output both fields of the child posts (directly) and fields from the parent, by using the id attribute (which will be generated automatically if you use the Fields and Views button and the post selection tab). If you want the parent fields to appear only once (not for each child), include them before the opening wpv-loop tag.

In the no-items-found section of this embedded View you output nothing (rather than the normal message).

That way for parents where there are no child posts, nothing will be output.

This support ticket is created 6 years, 4 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by randallH-3 6 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#948954

I created 2 views:

1st for the main list of the content
2nd for the "notes" of child posts of the list, inserted on the 1st view

Everything works fine, but how can I remove all items that don't have specific child post type?

#949081

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You want to only show parent posts that have child posts and omit those that don't?

The most efficient solution would be a custom query requiring table joins, but that's stepping outside of what we can offer here.

The Toolset-way would be to have an outer View which returns all of the parent posts, which does not output any fields from the parent itself, and only contains the embedded View to return all of the child posts from each parent.

Then in the output of this embedded View you can output both fields of the child posts (directly) and fields from the parent, by using the id attribute (which will be generated automatically if you use the Fields and Views button and the post selection tab).

In the no-items-found section of this embedded View you output nothing (rather than the normal message).

That way for parents where there are no child posts, nothing will be output.

#949384
Screen Shot 2018-07-18 at 9.14.57 AM.png

How can I make the parent show only once if it has multiple children but show all the children?

<ul>
		<wpv-loop>
                [wpv-conditional if="( '[wpv-current-user info='login']' eq '[types field='note-user'][/types]' )"]
<li style=" margin: 5px; list-style-type: square;">
  [wpv-post-featured-image id="$proof-point"]
 [wpv-post-link id="$proof-point"]
  [wpv-post-type show="single" id="$proof-point"]
          [su_expand more_text="View / Edit / Delete" less_text="Hide" height="20" text_color="#333333" link_color="#0088FF" link_align="left"][wpv-post-title]<br/><div style="padding:2%; background-color:#f1f1f1;">[cred_form form='edit-note']</div>[/su_expand]</li>

          
          [/wpv-conditional]
      		</wpv-loop>
</ul>

For this example, I used unordered list. Please check screenshot.

#950085

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

In the second View which is displaying fields both of the parent and of the child posts, you can display the parent fields outside of the loop, i.e. immediately after the wpv-items-found shortcode but before the wpv-loop tags.

They will show when there are child posts, but only once.

#951650

Thank you.