Skip Navigation

[Resolved] Only show child posts in a View if there are any

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

Problem:
A View to list child posts shows "No results found" when there are no child posts but should show nothing.

Solution:
Delete the text "No results found" from the Loop Output of the View so that no text is shown, as described in the first reply below.

This support ticket is created 6 years, 6 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)

This topic contains 2 replies, has 2 voices.

Last updated by AtefR7377 6 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#904740

Hi,

I have a CPT called "Books" and another CPT called "Chapters".

I want to create a view that displays the children "chapter" posts in the parent "book post.

this is very easy and I achieved this.

however, when the book doesn't have children, it gives "no posts found". also, I want to display a header above the chapters list.

therefore, I wanted to use conditional in either of the following ways:

1- if the parent book has a certain category (that i will assign to the books that have chapters), then show the children, or
2- if the parent book has children posts, then display these children.

however, i can't find a way to do either solutions.

i tried this code, but it did not display anything:

[wpv-conditional if="( '[wpv-taxonomy-slug]' eq 'html-books' )"]
[wpv-view name="chapters-view"]
[/wpv-conditional]

i tried to add a filter for the view "chapters-view" to say: if the parent has taxonomy X, display the results, but couldn't do so.

can you please advise a solution to the above case?

thanks in advance.

#904822

Nigel
Supporter

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

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

Hi Atef

The simplest solution to "No posts found" showing when there are no child posts is to edit the child post View and delete that text from the Loop Output Editor so that the wpv-no-items-found shortcode contains nothing, in which case nothing will be output when there are no child posts.

If you want to display a head above the chapters list that appears only when there are chapters, then you can add that header in the same Loop Output Editor of the same child View, immediately after the opening wpv-items-found shortcode (so that it appears when there are child results) but before the wpv-loop tag (so that it only appears once and not for each child post iteration).

#905068

thanks Nigel. very much appreciated