Skip Navigation

[Resolved] Filter a view by a custom field in the PARENT CPT

This support ticket is created 3 years, 10 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 Silvia 3 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1619363

Hi, I really hope I can clearly explain my problem, I am sorry if it's a little verbose, but I am trying to explain the situation as detailed as I can so that you can better understand what I want to achieve.

I am restyling the website that belongs to the regional section of the trade association for which I work. It is an association of craftsmen with 11 different federations (Food, Wellness, Car repair, Construction, Transport, Fashion etc ..), each of which respectively include a list of different professions. For example Wellness Federation includes the professions of hairdresser, beautician, masseur, make up artist, etc.

Each federation, profession, corporate body, group, as well as the Association itself, has its own board of administration that NEED to be visible on the website. All these boards are made up of associated artisans who can hold multiple positions within the Association: for example, an associate hairdresser can be President of the hairdressers, Vice President of the Wellness Federation and also President of the Association. My client asked me to keep track of all the people involved, and all the positions they hold within the Association.
In order to manage all these informations I did the following:

1. I created a CPT for the FEDERATIONS
2. I created a CPT for PROFESSIONS
3. I have created a CPT for PEOPLE
4. I created a CPT for FEDERATION OFFICES
5. I created a CPT for PROFESSION OFFICES
6. I created a ONE TO MANY RELATIONSHIP, where A FEDERATION can be connected to MANY PROFESSIONS
7. I created a RELATIONSHIP ONE TO MANY between FEDERATION and FEDERATION OFFICES where a FEDERATION has MANY OFFICES on its board.
8. I created a ONE-TO-MANY RELATIONSHIP between PROFESSIONS and PROFESSION OFFICES where a PROFESSION has MANY OFFICES on its board.
9. I created a ONE-TO-MANY RELATIONSHIP between PEOPLE and FEDERATION OFFICES where A PERSON can be connected to MANY FEDERATION OFFICES
10. I CREATED A ONE TO MANY RELATIONSHIP between PEOPLE and PROFESSION OFFICES where ONE PERSON can be connected to MANY PROFESSION OFFICES

I have also created other CPTs for other groups or corporate bodies that have their own board of administration, but are basically created on the same principle as those described.

Given that my client asked that each inserted PERSON, if requested by virtue of the privacy law, should be "disabled" from the site in any place where they appear, I inserted a radio button in the PERSONAL custom fields to determine whether that person is VISIBLE OR NOT within the site.

When I went to create a view for FEDERATION OFFICES and I filtered by the following:
A) that the field “FEDERATION OFFICE VALIDITY” which is part of the custom fields for FEDERATION OFFICES has value "YES"
B) that the “VISIBLE field which is part of the custom fields for PERSON (which is A PARENT) has value "YES"

The view processes the first filter but cannot process the second. Did I plan relationships in a wrong way? Is there an alternative way to make it work?
I would like to be able to filter each set of OFFICES, be they for FEDERATIONS, CRAFTS, or whatever, so that they only show "visible" people.

#1619711

Nigel
Supporter

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

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

Screenshot 2020-05-11 at 12.26.47.png

Hi Sylvia

Filtering by fields from related posts is currently not supported (I've added this thread to the internal ticket for this so we can track the demand).

In your case I think what you can do is remove the filter for the visible field, meaning that the View query will return all the posts regardless of the field value for the parent person posts.

But then in the output of the View you can wrap the output in a conditional shortcode which tests the field value for the parent.

If you use the conditional output button in the output section of the View to insert a test for the visibility field you can specify that the post to test should be the parent of the current post.

You can see me doing something similar in the screenshot (although my field is called "Selectors" and my related posts are "Projects"), which generates a conditional shortcode like this:

[wpv-conditional if="( $(wpcf-selectors).item(@project-post.parent) eq '1' )"]

(The item attribute specifies that something other than the current post is being tested.)

#1619871

It was easier than I thought and your solution worked like a charm. I even tried to implement it using blocks instead of coding it into the content template of the "old fashion" view, and I cannot thank you enough!!! My issue is resolved now. Thank you!

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