Skip Navigation

[Resolved] Custom fields from Relationship not displaying in View

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

Problem:
How to output relationship fields when displaying one of the relationship post types in a View?

Solution:
When you output the field using a types shortcode it needs to include an item attribute that specifies that the post source if the intermediate post type where the relationship fields are stored, like so:

[types field='priority' item='@left-right.intermediary'][/types]

Using the Fields and Views button to insert the field—and specifying the source in the Post Selection tab—will ensure the correct format for the shortcode.

This support ticket is created 6 years, 2 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
- 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 2 replies, has 2 voices.

Last updated by Ben 6 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1096765

Ben
View QF.png
View Loop Fields.png
Type selected in view.png
Relationship within Parent.png
Relationship within Child.png
Relationship.png
Output.png
Loop Editor.png

I am trying to display custom fields from a Relationship in a View.

I have set up the Relationship. Connected the Posts and populated the Custom Fields. But I cannot seem to get these Custom Fields to display in the View Output.

Can anyone see what I am doing wrong?

#1096905

Nigel
Supporter

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

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

Screen Shot 2018-08-31 at 11.40.12.png

Hi Ben

You have a Test CPT and Test CPT 2 in a many-to-many relationship where relationship fields are stored on an intermediary post type test-relationship, correct?

And you are trying to display the relationship fields?

I'm not clear where you are trying to display them.

Let's say you are showing a single Test CPT post, and you want to display the related Test CPT 2 posts on that same page, together with relationship fields from those connections.

So you will edit the template for single Test CPT posts and insert a View.

That View will display Test CPT 2 posts.

It will include a Query Filter so that it only shows Test CPT 2 posts in a relationship with the current Test CPT post (i.e. "Select posts in ... the relationship... that are related to the Post where this View is shown").

Then in the Loop Output section you might output the title of the Test CPT 2 post, and then the fields from the relationship for each combination of the Test CPT post being shown and the Test CPT 2 post in the Loop.

If you use the Fields and Views button to insert these fields you will see a Post Selection tab, which lets you specify which post should be the source for the field values.

In the screenshot you can see I am selecting the intermediary post type of a Lefts-Rights post relationship as the source.

That will add an item attribute to the types shortcode, something like this:

[types field='priority' item='@left-right.intermediary'][/types]

Does that cover your use case or were you looking for something different?

#1102564

Ben

Thank you Nigel!

Using the Fields and Views button with your instructions has allowed me to achieve exactly what I needed.