Skip Navigation

[Gelöst] How to display fields of related posts in a many-to-many relationship

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
How to display fields of related posts in a many-to-many relationship that are connected by an intermediate post type?

Solution:
To traverse the relationship from one post type, via an intermediate post type, to a second post type, you need to first create a View which returns the intermediate posts that are children of the first post, and then in the Loop Output section of that View use the id attribute on the shortcodes to display fields from the connected posts.

Described more fully below: https://toolset.com/forums/topic/custom-search-results-displaying-content-from-two-cpt-combined-with-intermediary/#post-625181

This support ticket is created vor 6 Jahren, 8 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 3 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von larryB-3 vor 6 Jahren, 8 Monaten.

Assistiert von: Nigel.

Author
Artikel
#625112
writer-cpt-post realtationship.png
CPT setup.png
Custom-search-articles.png

I have two Custom Post Types. "Member Profile" and "AAIMCo Articles". They both share a custom taxonomy called "Areas of Expertise".

They are setup as parents to a "Writers" Custom Post Type. I use this "Writers" CPT as an Intermediary to combine Member Profiles to the articles they write.

I am doing a custom search of articles using a [wpv-control-post-taxonomy]. I get the "AAIMCo Articles" Post Fields to display in the Loop Output correctly. You can see it working at versteckter Link

I cannot get the "Member Profile" post fields that are connected via the "Writers" CPT to display however in these search results.

You can see from the screenshot how I have this custom search set up. Seems like it should work? How do I make it work?

thank you for your help.
Ronald E

#625181

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

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

Hi Ronald

Your post type structure looks something like this:

Member   Article
   \      /
    \    /
    Writer

Your View shows Articles.

In the output section you can display fields of articles, or using the id attribute you could display fields from posts that are parents of articles. But articles don't have parents. (You should remove the id="$article" from the shortcodes, you are already displaying article fields here.)

If you want to display fields from the member posts you need to traverse the relationship to access them.

So from article you need a View which returns writers that are children of the current article, and then in the output section of that nested View you can use the id="$member" attribute on the shortcodes to display fields from the parent member post.

You use a View to look down, and the id attribute to look up.

Does that make sense?

#625479
the-fix.png

Thank you NIgel. That was the perfect answer!

#876663

Delete.