Skip Navigation

[Resolved] Showing data from a relationship in a view

This support ticket is created 2 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Waqar 2 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2265751

Tell us what you are trying to do?
I am currently working on a view. Obviously adding fields for the chosen post type is working well, but I would like to include data from a "related" post type. Is this possible in a view?

Is there any documentation that you are following?
I've not found documentation for this, but I may be looking in the wrong place.

Is there a similar example that we can see?
No sorry, I've not found one.

What is the link to your site?
My development site is at hidden link

#2266175

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

Yes, it is possible to show the related post data, using the "item" attribute:
https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/

For example, the "[wpv-post-title]" shortcode shows the title of the current post in the view's loop:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-title )


[wpv-post-title]

Now, suppose that you have a one-to-many relationship ( relationship slug "author-book" ) between "Authors" and "Books" post types so that one author can have many books. To show the title from the related author post in the view for the books posts, you can use the item attribute with the same "[wpv-post-title]" shortcode, like this:


[wpv-post-title item="@author-book.parent"]

Similarly, you can use the item attribute with other Toolset shortcodes too:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/
https://toolset.com/documentation/customizing-sites-using-php/functions/

Important note:
This item attribute method will only get information from one of the related posts. To get the list of more than one related post, you'll need another post view, as explained at:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2266349

Hi Waqar thank you for this information, I will work through your suggestions. I've not tried to do something like this before, so this is very helpful.

#2266353
toolset-relationship01.jpg

Hi Waqar yes in this case the relationship is many to many (see attached), so I'm guessing I need to look at the last link you sent through?

#2266371

OK I've read through this reference: https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items

I can see how the data could be displayed, the problem I have is I'm mixing data from the "Articles" post type and then wanting to add data from the "ACNR Authors" post type. So I'd like to display the title (and link) of the five latest articles in a view together with the authors that wrote the article (which will be in the ACNR Authors post type). So if I'm understanding this correctly, those two bits of data need their own views? Am I understanding that correctly?

So can you mix two view on the same layout?

#2268341

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back and glad that my message helped.

If your goal is to show the "ACNR Authors" posts related to each of the five latest "Articles" posts, then yes you'll need to use two separate post views.

1. The parent view will be set to show the latest 5 "Articles" posts.
2. The child view will be nested in the loop of the first view, so that it shows the related "ACNR Authors" posts in relationship with the current "Article" post in the parent view's loop.

Important note: Nesting of views is not supported in the blocks-based views, so for this, you'll need to create both these views using the classic/legacy views editor.
( ref: https://toolset.com/documentation/legacy-features/views-plugin/ )

We have a guide on the nesting of views at:
https://toolset.com/documentation/legacy-features/views-plugin/using-a-child-view-in-a-taxonomy-view-layout/

#2269625

Thank you Waqar appreciate the info!

#2270363

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

You're very welcome and let me know if you have any follow-up questions.

For a new question or concern, please start a new ticket.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.