Skip Navigation

[Resolved] Filter a view using parent of the posts in the loop

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

Last updated by christineC 2 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2408741

Tell us what you are trying to do?
I have two post types with a one (parent) to many (child) relationship. On each child page I need to output a list of all the child pages belonging to the parent of the current child page. Every child page needs this list so I need to loop through them all in a view.
Is there any documentation that you are following?
I found some relevant information on this page: https://toolset.com/documentation/user-guides/views/filtering-views-query-by-post-parent/ but the information is not complete enough to understand exactly how I set it up.
Is there a similar example that we can see?

What is the link to your site? dev.rusoffagency.com

#2408959

Hello,

I assume we are talking about Toolset one-to-many relationship, if it is please try these:
1) Create a content template "parent-post-information", display below post view "related child posts view":
- Query "child" posts
- Filter by:
Select posts in a {YOUR-ONE-TO-MANY} relationship that are related to the Post where this View is shown.
- In view's loop, display the the child post information
2) In the single child post, display above content template shortcode with item attribute, for example:
[wpv-post-body view_template=""parent-post-information"" item="@{YOUR-ONE-TO-MANY-SLUG}.parent"]

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/
If your current post is in a relationship acting as child post, you can use the value of @{relationship-slug}.parent to obtain data from the related parent.

#2409439

I'm only getting the current post title in my list. There should be 4 titles as there are 4 Additional Book Info posts related to the parent book.

Here is my code:

At the top of the Loop in the View:
[wpv-post-body view_template="parent-post-information" item="@fiction_book-info.parent"]
[wpv-post-body view_template="parent-post-information" item="@non_fiction_book-info.parent"]

The loop:
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-post-link]
</wpv-loop>
<!-- wpv-loop-end -->

My Template:
[wpv-conditional if="( '[wpv-attribute]' eq '@fiction_book-info.parent' )"][wpv-post-link item="@fiction_book-info.child" class="sep-book"][/wpv-conditional]
[wpv-conditional if="( '[wpv-attribute]' eq '@non_fiction_book-info.parent' )"][wpv-post-link item="@non_fiction_book-info.child" class="sep-book"][/wpv-conditional]

Relationship:
Fiction Book > Additional Book Info (relationship slug is fiction_book-info
Non Fiction Book > Additional Book Info (relationship slug is non_fiction_book-info

Both relationships are one to many

#2410631

To avoid wrong settings, I suggest you try different content templates for each post type relationship, so you don't need to use [wpv-conditional] shortcode in those content templates.

#2412775

I’ve gone a different direction by following the instructions on this post: https://toolset.com/documentation/legacy-features/views-plugin/displaying-related-child-posts/#using-views-only

I also am just trying to start with just one post type instead of using conditionals. I was able to get all the child pages to show up in the list. If I am not logged in to WordPress, the list looks fine but there is other information displaying above. If I am logged in and viewing the front end, I see multiple infinite loop errors in red.

#2412853

Please share a test site with same problem, fill below private message box with login details, also point out the problem page URLs, I need to test and debug it in a live website, thanks

#2413479

My issue is resolved now. Thank you!