Skip Navigation

[Resolved] Confusion in displaying relationship data

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 3 replies, has 2 voices.

Last updated by Nigel 2 months, 2 weeks ago.

Assisted by: Nigel.

Author
Posts
#2742881

Tell us what you are trying to do?

Hi there, we have a relationship set for custom post types. "Owners" are associated with "Artworks" in a "Former Owners " Relationship. This is so that we can display historical owners of a given artwork piece. We also have a "Current Owner" relationship with "Artworks" & a single "Owner" which is easy to query within a single view (loop).

We're having issues on querying the "Former Owners" relationship to display ALL of the "Former Owners" established in the relationship. The confusion is that a many to many relationship is set for this relationship. And so we're not sure if a parent/child relationship exists - as I don't think that relationship is necessarily a hierarchy.

How would we accomplish displaying a view that will query this relationship so that we can embed that in a parent loop that will for example display all types of artwork on a given page?

The artworks post types would display on this page, and with each artwork within the parent loop, we'd like to list all of the "Owners" connected to the "Artwork" within the "Former Owners" relationship.

We're stuck in querying/displaying this data. What are we missing here?

What is the link to your site?
hidden link

#2743365

Nigel
Supporter

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

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

Hi there

When displaying related items of a many-to-many relationship, you must use a View.

Given that you want to output the results of this in the loop output of another View, then you will be nesting Views.

It's not clear if you are using the legacy Views editor (where this is straightforward) or the newer Blocks editor (which is less so).

But you need to make a View to query the related posts, where you will add a post relationship Query Filter, and rather than selecting related to the page where the View is shown you will choose related to the current post in the loop.

You then insert that View in the Loop Output section of the first View where you need it displayed. (With the Legacy editor that means inserting the wpv-view shortcode; with the Blocks editor I would also recommend inserting the View that you made elsewhere via shortcode.)

If you need more guidance let me know, I'm not sure how familiar this is to you.

#2743551
Screenshot 2024-09-10 at 9.57.02 AM.png

Hey Nigel,

- We're using the legacy views editor currently and are fairly comfortable with toolset generally. Logically I understand what you're explaining on what we need to do, yet something is still a miss in querying the data for the Former Owners Relationship. Making single queries, to a relationship is quite easy, it's when we try to loop relationship data where we hit a brick wall.

- I think it would be easier to focus on querying a single Artwork post to display first before we work on this in other looped views on the site. The aim is to print the Post Titles of each "Former Owner" in the relationship for a single Artwork Post type.

- So for now, how do I display the former owner post titles on a single Artwork Post type?
(attached image of the former owners of an example Artwork Post). The Artwork is a single custom Post type, and the Owner is a single custom Post type in which a "Former Owners" Relationship exists in a "many to many" connection.

(I'll post what I think the settings should be for the view to display the former owners of a single artwork custom post on its specific post page) :
----- Content selection: (Artists Post Type)
----- Query Filter: Select items in the Owners Artworks relationship as related items of... The post where this View is shown
----- Loop Wizard: Unordered list, Post title > A post related to the current post, set by a Types relationship > Former Owners (many-to-many relationship) > "Owners"

- Even in trying to use this shortcode on the single artwork display view - we're still coming up empty-handed.

#2743566

Nigel
Supporter

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

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

In this scenario your starting point is a single Artwork post.

You want to display the Owners linked via the "Former Owners" relationship.

So, your View content selection should be Owners.

To this you add a post relationship Query Filter to only return Owners that are connected via the Former Owners relationship to the page (Artwork post) where this View is shown.

Then in the output section just output the post title; the loop output will be iterating over Owner posts, because that's what the View queried, so you just output the post titles for the "current" post.

You'll do the same when it comes to nesting a similar View in the output of a View to display Artworks added to some page, but the difference will be in the settings of the Query Filter. Instead of the current post being the page where the View is shown, the current post will be the current item in the parent loop.

Does that clarify things?

#2745678

Hey Nigel,

Thank you for clarifying a few things for us.
I think we had a few things wrong in our setup regardless of the issue we found (below).

We've found part of the issue as to why the views were not showing correct output. Part of the reason was that during our testing, we accidentally "deleted" a couple of "Owners" in the relationships on the Artworks Post Edit page. In realizing this deletes the "Owner" altogether, we quickly realized that we need to "restore" the "Owner" on the same page. Even with this restoration, we didn't realize that the restore sets that "Owner" post type to "Draft" and thus would not display in our views output, which set a false expectation that the view was incorrect (it still may have been).

Once we used your suggestion above, and set the "Owner" drafts to "Published" - we then were finally successful.

To Recap:

1) Thank you for your support & suggestion

2) If the feedback doesn't exist for your team:

Please consider displaying "Draft" or some sort of indicator for Relationship connections that are not published and not displayable. I think we could have saved a lot of time understanding that and/or seeing that indication after the "restore" / during the restore.

Have a great weekend.