Skip Navigation

[Resolved] Hiding parents with no children

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by Minesh 8 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2687881

Hello,
I have two classic views, the first one looping on parents and a second (nested) one looping on children of a one-to-many relationship, output on the page is like this:
PARENT1
CHILD1
CHILD2
CHILD3
PARENT2
CHILD1
CHILD2
PARENT3
No items found

Is there a way not to show parents like PARENT3 which have no children ?
Thanks
Regards
Nicola

#2687907

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share what content you have inside:
- Parent View "Loop Editor" section
- Child View "Loop Editor" sectinon

#2687921

Hello Minesh,
In the parent view template I simply call the child view like this:
[wpv-view name="planned-events-events-children"]
Both loops are standard, see below.
The child view has a Filter by post relationship active.
Should I do it differently ?
thanks
Regads
Nicola

Parent loop
--------------------------
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-body view_template="loop-item-in-planned-events-pubs-parent"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

Children loop
------------------------------
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<table>
<wpv-loop>
[wpv-post-body view_template="loop-item-in-planned-events-events-children"]
</wpv-loop>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#2687922

Minesh
Supporter

Languages: English (English )

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

Its not clear to me where you are displaying the parent post title or link.

Can you please share edit view screenshot of both parent and child view page.

#2687928
child.jpg
parent.jpg
S1.png

please see attachments

#2687949

Minesh
Supporter

Languages: English (English )

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

Can you please try to follow the following steps:
1)
In the parent view template I simply call the child view like this:
[wpv-view name="planned-events-events-children"]
====>
Please remove the view's shortcode you added to parent view's template and save the parent view.

<div style="......"> [wpv-view name="planned-events-events-children"] </div>

2)
Adjust the view's loop editor for both parent and child as given under:

Parent loop
--------------------------

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-view name="planned-events-events-children" parentid="[wpv-post-id]"]
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

Children loop
------------------------------

[wpv-layout-start]
[wpv-items-found]

[wpv-post-body view_template="loop-item-in-planned-events-pubs-parent" item="[wpv-attribute name='parentid']"]

<!-- wpv-loop-start -->
<table>
<wpv-loop>
[wpv-post-body view_template="loop-item-in-planned-events-events-children"]
</wpv-loop>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"][/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

As you can see we added the parent view template after the shortcode: [wpv-items-found] in child view

[wpv-post-body view_template="loop-item-in-planned-events-pubs-parent" item="[wpv-attribute name='parentid']"]

That means the parent template only called when there is child post found and if found we assign it the parent id using the shortcode: [wpv-attribute name='parentid']

Can you please try and test.

#2688109

Hello Minesh,
Your solution works, but there is a strange behaviour of the pagination. I set the pagination to max 5 parents per page in the parents view and in output the first page is empty while other pages show one parent only (with correct children) and many other empty pages afterwards. Removing the pagination the output is correct.
Please let me know.
thanks

#2688111

Minesh
Supporter

Languages: English (English )

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

Yes - obviously it will affect the pagination because you are not displaying the parent post when there is no child post.

#2688112

Unfortunately in this context I need the pagination because parents with children will be many, the page would be VERY long ! any clue ? what about replacing the normal pagination with buttons ?

#2688116

Minesh
Supporter

Languages: English (English )

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

That is different issue.

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.

I split the ticket for your pagination issue and handle with the following ticket.
- https://toolset.com/forums/topic/split-hiding-parents-with-no-children-show-pagination-or-adjust-pagination-when-hiding-parent-post-when-no-related-child-available/

You're welcome to close this ticket.