Skip Navigation

[Resolved] How to filter by grandparents

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

Problem:
Client has a sequence of parent > child relationships and wants to include a filter for the grandparent or great grandparent posts in a View which shows child posts.

Solution:
It is only possible to filter by immediate ancestors, i.e. parents rather than grandparents etc.

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

Last updated by Ljuba 5 years, 7 months ago.

Assisted by: Nigel.

Author
Posts
#1088166

==> Tell us what you are trying to do?

I have Hotels parent post and Rooms as child post. Rooms are with (ie) Bathroom Amenities taxonomy (terms).

Is it a way to filter Hotels per Rooms Bathroom Amenities?

P.S. They are displayed in Query, but nothing appear, as obviously some relationship should be set, but ...?

So, code below, don't display anything (except title)

<div class="form-group">
	<label>[wpml-string context="wpv-views"]Room amenities[/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="room-amenities" type="checkboxes" url_param="wpv-room-amenities"]
</div>
#1088304

Nigel
Supporter

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

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

We will soon release a major Views version, and work is about to begin on the next development cycle for Views.

Filtering by fields of related posts will be added in that version.

With WordPress queries you can only filter something by its own properties.

So you would only be able to filter hotels by fields (standard/custom/taxonomies) of hotels.

We have partly expanded on that with M2M relationships, in that you can with Toolset also filter by relationship fields (i.e. custom fields which are stored on an intermediate post type).

The final piece of the jigsaw is to extend that further to be able to filter by fields of the related posts themselves (e.g. filter hotels by whether it has rooms with en-suite bathrooms).

(Unfortunately, the UI lets you insert such a filter in a View, using fields that belong to a related post rather than the posts being queried, but it doesn't work and doesn't warn you that it won't.)

Including testing, it may take a couple of months before that version of Views is published (obviously this is not the only feature being worked on).

#1088368

Thanks. Clear.

#1088369

Sorry to reopen. One additional question (to not waste my time to explore it).

So, if I will in some way found how to organize archives and found how to place within such organization also Rooms archives > Can I search like this within ALL ROOMS OF THE SITE? (I guess, yes, but to ask), I mean, I can 'fake' rooms archive views trough 'hotel' (if you get me).

#1088404

Nigel
Supporter

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

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

Yes, you can filter by some field of rooms (e.g. "has ensuite") for *all* rooms posts, which would list rooms with en-suite bathrooms, and then, what?, you can display fields from the parent hotel rather than (or as well as) fields from the room.

Is that what you mean?

#1088408

No, I thought to create links on Hotels archive page (at same place where are filters), as "Looking for particular room?" > what should to open Rooms archive page with filters and part of the Room Views (listing) will be basically That room, but with clear assignation to the Hotel ownership (ie Individual Room of Holliday Inn), what should to enable visitors to search for rooms with particular characteristics and than will lead the visitors to the Room?Hotel page (depends on what link within listing view will click).

Question is > than such Rooms archive page can contain filter with Hotels, or City, ... (some parent psots), right? (when visitor have final list of characteristic, to be able to 'strech' results even more.

#1089358

Nigel
Supporter

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

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

OK, I understand.

Yes, on your Rooms archive you could add query filters for parents, e.g. for the Hotel a room belongs to, as well as filters for fields and taxonomies of Rooms themselves.

You mentioned City, but is City a field of Rooms or a parent of Rooms? If not you couldn't filter by City.

I need to make a correction to what I wrote above: "you can with Toolset also filter by relationship fields (i.e. custom fields which are stored on an intermediate post type)". It seems I was getting ahead of myself, that is also something that will be added in the next Views dev cycle.

#1089417
01.png

You are right, I should to stick to the terminology what is used in website, as you are familiar with it. So, my 'chain' is:

Destino > Negocio > Alojamiento > Habitacion > Cama

Question is > in Habitacion archive can be added search filter for ALL PARENTS or just for the first parent (see image). I can't see Destino (that what I ment as City). Is it because I didn't assigned it yet for current Negocio or something else is problem?

P.S. Screenshot is from Alojamiento archive, so I have naively Negocios as first parent and at moment I can't test it all to be able to know the answer by myself.

#1089431

Nigel
Supporter

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

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

The problem is Destino is not a parent of Habitación, it is a great great grandparent.

You can only add filters for parents.

#1089434

OK. All clear. Thanks.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.