Skip Navigation

[Resolved] Displaying related information based on intermediary post field

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 7 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2703581

Tell us what you are trying to do?

I have two post types - Teams and Coaches.
I have a many-to-many relationship set up between the two post types:
-- Teams can have multiple coaches
-- Coaches can coach multiple teams

Each coach is designated as a head coach or an assistant coach for each team they are associated with. So I created an intermediary post for the relationship between teams and coaches with a checkbox list field so I can do those assignments.

So far so good.

Now, I want to display the coaches on the page for the team. So I created two views:

-- Team Assistants
-- Team Head Coach

Both of them I've filtered as follows:
Filter by post relationship or repeatable fields group owner
Select posts in a Coaches Teams relationship that are related to the Post where this View is shown.

That works - it pulls in all the coaches assigned to the team.

However, I can't get the second filter so I can show the Head coaches separate from the Assistant coaches.

I can see the field I want to filter on in the filter options: Custom Field: Role On Team.
I've tried all the combinations of "strings" or "Numbers", but nothing makes the filter work.

The "Role on Team" field associated with the intermediary post is a Checkboxes field.
I have "Value to store" for the Head coach set to 1 and
the Value to store for the Assistant coach set to 2.

Thus, I would expect the filter to have logic like this:

For head coaches, I set the filter as "Role on Team" is a Number equal to 1.
For head coaches, I set the filter as "Role on Team" is a Number equal to 2.

I also tried "String" instead of number - that didn't work either

However, in both cases, I get no results.

The Team I'm working with is this one: hidden link

I'm removed the second filter for the view for the assistant coaches so you can see both coaches assigne

You'll see two people listed under Assistant Coaches. Right now, that is both coaches currently assigned to this team.

Brian Bacchi is the assistant coach
Steven Abbott is the head coach - he should be appearing by himself under "Head Coach" based on the filter I have set.

#2703679

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share admin access details and let me check how you configured the view.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2704098

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

The thing you should remember is:
- you can filter the view results using the custom fields or taxonomies that are attached to post type you set your view to query.

In your case, you set your view to query the post type "Coaches and Leaders" but the custom field filter you added using "Query Filter" for the field "Role on Team" is part of the intermediary post type "Coaches Teams Intermediary Posts".

So, that you can not filter view result as the field "Role on Team" is part of the intermediary post type "Coaches Teams Intermediary Posts" and you set your view to query post type "Coaches and Leaders".

To make this work as expected, I've created another view "view-query-intermediary-custom-field" and set that view to query post type "Coaches Teams Intermediary Posts" and added the post relationship query filter as well as custom field "Role on Team" query filter to this view as given under:
=> hidden link

Filter by post relationship or repeatable fields group owner
Select posts in a Coaches Teams relationship that are a related to the current post in the loop.

Custom field filter
Select items with field:
Role on Team is a number equal to 1

And in this view's loop Editor I've added the following code:

 <div class="coach-container">
  <div class="coach-image">
     [wpv-post-featured-image item="@coach-team.parent"]
    </div>
  <div class="coach-name">[wpv-post-link item="@coach-team.parent"]</div>
</div>

And added the above view "view-query-intermediary-custom-field" within the following "team-head-coach" view's loop template. I've also uncheck the checkbox "Don't include current page in query result" for the following view.
=> hidden link

[wpv-view name="view-query-intermediary-custom-field"]

I can see it working as expected. Can you please confirm it works as expected at your end as well.

#2704854

Thank you! Just what I needed. I had a feeling I was missing a piece - and there it is. Works like a charm. I appreciate the help!