Skip Navigation

[Resolved] How to filter child posts by more than one parent

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

Problem:
Client has a child post type with two relationships, so more than one parent (of different types), and would like in a View to be able to filter by both parents.

Solution:
It is a limitation currently that only one post relationship filter can be included in a View at once. In the client's case, the relationships were better made with custom taxonomies, which then made filtering by both possible.

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

Last updated by roulartaM 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1226259
database-structure.jpg

*** Tell us what you are trying to do? ***
=> First of all, I would like to refer to my database structure again (see attachment ). My question is about three tables within that structure:

- shops (toolset name: "Winkels")
- shop_types (toolset name: "Winkel types") (possible values ordered by importance: "Premium", "Plus", "Basic", "Free")
- categories (toolset name: "Categorieën") (possible values: "Location & food", "Outfit", "Experience", "Gifts")

I've made 2 relationships so I can select all related data in the admin pages:

Winkel types [0 .. 1] << Winkels [*] (toolset name: "Types") (one to many)
Categorieën [0 .. 1] << Winkels [*] (toolset name: "Winkel categorieën") (one to many)

With this setup, a single shop can be assigned as shop type "Premium" and as category "Gifts".

On my page "Shops" (NL: "Winkels), I sorted my shops in 2 steps:

1) Sort by shop_types: "Premium" should go first, then "Plus", followed by "Basic" and finally "Free"
2) Sorted randomly for each child per shop_type.

I managed this in three toolset steps:

1) I've created a content template "Winkel" with HTML of one single shop
2) I've made a view "Winkels per winkel type" with the content template "winkel" loaded into it and with the following filter: "Filter by post relationship or repeatable fields group owner" => "Select posts in Any relationship that are a related to the current post in the loop."
3) I've made a view "Winkel types" with the view [wpv-view name="winkels-per-winkel-type"] loaded in it.

So far so good, here's the working example hidden link

But now, finally, my question / what I'm trying to do:

I have 4 category pages:

hidden link
hidden link
hidden link
hidden link

In each category page, I want to display the same view ([wpv-view name="winkels-per-winkel-type"]) as discribed above. The only thing is: the shops should be linked to the selected category.

So each category should iterate the shops related to that category, ordered by the shop type ("Premium", "Plus", "Basic" and finally "Free") and then ordered randomly.

Can you support me on this one please? If needed, I can give you the credentials to log in the WP-admin 🙂

*** Is there any documentation that you are following? ***
I've got some idea's by the following URL: https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

*** Is there a similar example that we can see? ***
No I guess 🙁

*** What is the link to your site? ***
hidden link

#1226327

Nigel
Supporter

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

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

Hi there

I'm not sure why you aren't using taxonomies for shop_types and categories which seem appropriate in this case, but, anyway, if you already have a View that displays the output you ignoring categories, can you not just add a Query Filter for categorie where the value comes from the page where this View is shown to your Winkel types View?

#1226379

Hi Nigel!

Thanks for your reply! I choose not to work with taxonomies because I really wan't to understand toolset. And also because there may only be one type or category related to a shop instead of multiple 🙂

I tried to understand where you were referring to, but I don't quit understand what my next step should be. The 4 categories on the website aren't pages, they're also made of a content template called "Sjabloon voor Merken".
I'm sorry if I'm not too clear with my explanation. If not, please tell me what info I can add 🙂

#1226425

Nigel
Supporter

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

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

Let's see if I've understood correctly.

hidden link is a static page on which you inserted the View Winkel types which queries the post type Winkel types. In the output section of this View you insert a nested View, winkels-per-winkle-type which queries winkel posts and includes a Query Filter to only show winkel posts related to the winkle-type from the outer View.

You want to insert the same View into the template to display categorie posts, so that when you visit a URL such as hidden link it displays the winkel posts in the same format as before, but only those with the relevant categorie.

Now that I write it out in full, it's clear that the additional filter needs to be on the inner, nested View, which is the View that actually queries winkel posts, to which the categorie posts are related.

So on that nested View, winkels-per-winkle-type, you will need to add a post relationship Query Filter for the winkel-categorie relationship where the categorie is determined by the page where the View is shown (e.g. hidden link).

You may need to duplicate your Views to be able to add this and still be able to use what you already have on the hidden link page.

#1227263
extra-filter.png

Hi Nigel,

the summery as you discribed is exactly what I need! 😉

I now duplicated the view 'winkels-per-winkel-type' to 'winkels-per-winkel-type-en-categorie' so I could add an extra Query Filter for the relationship 'winkel-category'.

But here comes the new problem: I can't select another 'Post relationship or repeatable field group owner' filter and that's standard Toolset functionality I've read before.

As you can see in the screenshot's grayed background, I already have the following filter:

Filter by post relationship or repeatable fields group owner
Select posts in a Types relationship that are a related to the current post in the loop.

Or perhaps I misunderstood what you were saying? I'm sorry to say so 🙂

#1227844

Nigel
Supporter

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

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

Ah!

Of course, it is a limitation with post relationships that you can only add a Query Filter for a single relationship at one time.

So, it is not possible what you are aiming for if using post relationships.

You can use posts and post relationships for winkel types, or categories, but not both, and should use a custom taxonomy for one or the other to get around the limitation. (Though as I said at the outset, it seems like both are good candidates for custom taxonomies.)

#1227850

Hi Nigel, thanks for that confirmation. It a small disappointment, but it's also a small relief. I know the limitations of Toolset now, so that's an advantage for my future developments 🙂
As you proposed, I'll try to use shop types and shop categories as taxonimies now. Thanks for your support answers!