Skip Navigation

[Resolved] Filter Archive by Child Relationship

This support ticket is created 8 years, 1 month 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+01:00)

This topic contains 11 replies, has 3 voices.

Last updated by Nigel 8 years ago.

Assisted by: Nigel.

Author
Posts
#427094

I have 2 custom post types with a intermediary post type to create a many-to-many relationship.

Album-Review
Album Credit
Artist

I can assign artists to the album reviews and vice versa.

On my Album review archive page I want to have a drop down that filters the reviews by artist. So someone can select the artist they want and then all their album reviews will show.

On the views filter for the archive page I cannot see anyway of doing this as it just lets me filter by fields on that post type. How do I create a filter based on relationships?

#427195

Tia

Thank you for contacting Toolset Support. I am happy to help you with this.

Album Credit is the intermediary post type, correct?

#427212

Yes, that is correct

#427344

I have got this working partially by doing the following

1. Creating a view for my intermediary post type "Album Credit"
2. Specifying the output of fields to be album review parent like:

[wpv-post-title id='$album-review']

3. Adding a filter to filter by artists:

[wpv-control-set url_param="wpv-pr-child-of" ancestors="music-artists"]
	[wpv-control-item type="select" ancestor_type="music-artists" default_label=""]
[/wpv-control-set]

Now when I select the artist from the drop down it shows all albums that they have been credited on.

However, because it shows every relationship, before an artist is selected the full list has duplicate albums in it.

How do I remove these duplicates? Is the way I have done this the preferred method?

#427484

Also if no artist is assigned then the review is not shown which is not ideal.

Ideally I want the initial page to display all album reviews. Then if an artist is selected from the drop down, only this artists albums are shown.

How can I achieve this?

#427800

Tia

Thank you for the feedback. Let me run a few tests on my end and I will return with results as soon as possible.

#428881

Tia

I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will request to duplicate the site and work in a separate, local development environment to avoid affecting the live site.

Privacy and Security Policy

We have strict policies regarding privacy and access to your information. Please see:
https://toolset.com/toolset-support-policy/privacy-security-providing-debug-information-support/

**IMPORTANT**

- Please make a backup of site files and database before providing us access.

- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this:

hidden link

#429772

Tia

Thank you for that information. I am looking into the issue and will respond shortly after investigating.

#431095

Tia

Apologies, have this added to the frontend yet? If so, can I have the URL? I would also like to test with the frontend display, if possible. Many thanks.

#431187

I didn't get it working so I haven't added it to the front end. Can you just tell me a way to create a filter for album reviews by artist and also have a complete listing of album reviews without duplicates?

#431733

Nigel
Supporter

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

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

Hi Mike

Tia is having connection problems so I'm taking over the ticket so that you are not left waiting too long.

When you create a custom search view (what we have up until this version been calling parametric searches), you are querying a particular thing (e.g. a custom post type) and the only things that you can filter that search by are fields on the thing you are querying.

They can be standard WordPress fields, or custom fields, but they must be of the thing you are querying. Post relationships look like a special case, but are not really, because post relationships are stored as a hidden custom field on the child (in a field with the naming convention of "_wpcf_belongs_post-type_id").

You are correctly employing the trick of querying one thing (Album Credit) while outputting content from something else (Album Review) by setting the id parameter to the parent. You are able to filter by Artist because Album Credit is a child post of Artist and so has the artist id stored as a custom field.

You are seeing duplicates of the Album Reviews because you are not querying Album Reviews you are querying Album Credits and there are multiple credits for the same Album Review.

To return only a single result for each Album Review you would need to be querying Album Reviews directly. But your Album Review is missing the custom field with the artist id so you can't filter by it.

This may get easier when work on overhauling post relationships within Toolset is completed, but that is probably a few months away and won't help you now: https://toolset.com/2016/08/how-post-relationship-replaces-post-reference-and-repeating-fields/

I'm sorry I don't have a solution for you, but hopefully that has helped clarify your understanding.

#431748

Nigel
Supporter

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

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

Mike, I was thinking a little more about this while I picked up a coffee.

While there is nothing you can do at the query level to stop getting multiple versions of the Album Review being returned, and until such time as Toolset posts relationships are modified, you could employ a bit of a hack on the front end to not display the duplicates.

You could add a little custom JS that runs on dom ready that iterates over the relevant part of your output and removes duplicates. You'll need to inspect the markup that is generated to identify what to use as your selector. It is a bit hacky but would give you the desired end result. The only real proviso is that it will mess with your pagination if you are using any.

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