Skip Navigation

[Resolved] Adding multiple relationship filters to archive page

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

Problem:
The user would like to use multiple relationships in the filters of an archive template.

Solution:
Currently, Toolset views cannot filter posts by more than ONE relationship. This is not supported yet. You can work around it with custom code, but that will require some programming skills. This can be leveraged in a way like:
- Custom code to generate the filters for secondary relationships. https://codex.wordpress.org/Shortcode_API
- Custom code to hook into the query filter and augment the query using the Relationship API. Check this article https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

Please note, that custom code, is out of the scope of this forum support. https://toolset.com/toolset-support-policy/

This does not mean that we won't help, we'll still help you if you encounter any issues with the provided API. If you are not comfortable with PHP programming, consider hiring a developer. Check our partners' page https://toolset.com/contractors/

Relevant Documentation:

This support ticket is created 3 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
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: Africa/Casablanca (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by Michelle Dodd 3 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#1717699

Tell us what you are trying to do?

I need to add multiple filter options to a directory page so users can filter by multiple relationship posts.

Is there any documentation that you are following?

I've read many different pages of documentation but I just can't figure it out

We have a main Custom post type called HCCN (Health Center Controlled Networks). I've set up multiple other CPTs as many-to-many relationships, such that each HCCN may have a few of each of these relationships. I need the directory (archive) template to allow users to narrow down the archive results according to the relationships. I'm attaching a JPG of the design comp showing the filters on the left side.

What is the link to your site?

The directory/archive page is here:
hidden link
password: health

I have the Electronic Health Records filter working, but it doesn't allow me to add another relationship filter like it shows here: https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/

#1717743

Also, I've converted the main HCCN single page, which shows all the data from the intermediary posts from relationships, to the block editor. But when I tried that for the HCCH archive page, it cleared everything out. So I went back to the older view style of editing the archive. I wonder if I'm going to have issues in the future if I don't convert the template to the new blocks editor? And does it have anything to do with getting the filtering by relationships to work? I saw this documentation, but it's using the blocks workflow: https://toolset.com/course-lesson/creating-a-custom-search/#2-6-filtering-posts-by-their-ancestors

Ugh.

#1718059

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

Currently, Toolset views cannot filter posts by more than ONE relationship. This is not supported yet. You can work around it with custom code, but that will require some programming skills. This can be leveraged in a way like:
- Custom code to generate the filters for secondary relationships.
- Custom code to hook into the query filter and augment the query using the Relationship API. Check this article https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

Please note, that custom code, is out of the scope of this forum support. https://toolset.com/toolset-support-policy/

This does not mean that we won't help, we'll still help you if you encounter any issues with the provided API. If you are not comfortable with PHP programming, consider hiring a developer. Check our partners' page https://toolset.com/contractors/

I wonder if I'm going to have issues in the future if I don't convert the template to the new blocks editor?
No, we still support legacy views. We do encourage our users to switch to the block experience though.

And does it have anything to do with getting the filtering by relationships to work?
Both legacy and blocks view should work the same way. If you encounter any issues with any of them, open a new forum thread or chat session and we'll help with it.

#1718247

Hi Jamal, thanks for your response. The link for augmenting the query makes sense in theory, how do I go about creating the filter on the front end to allow users to filter down by the other relationships?

Thanks,
Michelle

#1718263

Also - where do I put the query code exactly? I think we can figure this out, but any hints on these things would really help.

With appreciation,
Michelle

#1720565

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello Michelle and my apologies for the late reply, I do not work on Sundays and Mondays.

how do I go about creating the filter on the front end to allow users to filter down by the other relationships?
The straightforward way is to create a custom shortcode that will generate the control filter for the other relationships. Then you can put the shortcode in the filters section if you are using the legacy views, or in a shortcode block if you are using the blocks editor.
Check WordPress documentation about creating shortcodes https://codex.wordpress.org/Shortcode_API

where do I put the query code exactly?
You can put the custom code in Toolset->Settings->Custom code, or in the theme's functions.php file, or in a separate/new plugin which will need to be activated.

#1723961

Thank you for your help. We will address this in another round of development and may need more help at that time.

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