Skip Navigation

[Résolu] View of related post to be filtered on checkbox field on intermediary post type

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem: I have a many-to-many post relationship set up with a custom field applied to the intermediary post. On the single post page for one of the post types, I would like to display all the related posts, filtered by the custom field on the intermediary posts.

Solution: Create a View of the intermediary post type, filtered by the custom field and also by post relationship, where the post is related to the current post or page. Then in the Loop, select the related post in the Post Selection tab when you insert any Fields or Views shortcodes.

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.

This topic contains 3 réponses, has 2 voix.

Last updated by Tim Elliott Il y a 2 années et 5 mois.

Assigned support staff: Christian Cox.

Auteur
Publications
#1239394

Hi support team

I have a many to many relationship as follows:
Events >> Events Event People >> Event Speakers
"Events Event People" has a custom checkbox field "Event People Role" with 2 options (advisor, speaker)

In the Events Content Template I want to show 2 views:
All Event Speakers that have "Event People Role" set to advisor
All Event Speakers that have "Event People Role" set to speaker

For the Query Filter I have one filter that uses:
Select posts in a Events Event People relationship that are related to the Post where this View is shown

This works to display all related Events Speakers, but I'm struggling to set up the filter to limit this by the "Event People Role".

I've tried -
Select items with field: Event People Role is a string equal to advisor
But this doesn't work (it give no results) - I guess it's trying to find that field value on the "Event Speakers" post rather than the intermediary post.

Is there some way to filter on this field or do I have to include all of them, and then use a conditional to filter by the intermediary field inside the loop?

Thanks

#1239491

Actually, I can't use a conditional to filter by intermediary field as this will mess up the loop wrap.

#1239506
1.png
2.png
3.png

Hi, in general it's best to take this approach:
- Create a View of the intermediary post type Events Event People.
- Add a post relationship Query Filter like the one you described: Select posts in a Events Event People relationship that are related to the Post where this View is shown. You cannot currently filter a View by related post fields, so the Content Selection must be the same as the post with the checkbox field.
- Add the checkbox custom field filter to filter only advisors.
- In the Loop, you want to display information about the parent Speaker. When you build the loop using the Loop Wizard, you can use the "Edit" button next to each field to select a related post. See 1.png and 2.png.
- If you do not use the Loop Wizard, you can use the "post selection" tab when inserting Fields and Views to select a related post. See 3.png and 2.png.
- Once this View is working as expected, you can duplicate the View and change the checkbox filter.

#1239527

Thanks Christian. That worked.