Skip Navigation

[Resolved] Showing one field from one custom post type related to another

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

Last updated by Minesh 1 year, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2656461

Tell us what you are trying to do?

I have a site with custom post types 'books' and 'book-authors', and a relationship of one to many (books - book-authors).

There is one custom field from 'book-authors' that I want to display on the 'books' template. That field should link back to the specific 'book-author'.

I'm using Elementor, and from what I've read I need to use a shortcode to display this? I read some answers here but they were a bit technical. Can someone give me an example I could use for this?
Thanks!

#2656697

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I have a site with custom post types 'books' and 'book-authors', and a relationship of one to many (books - book-authors).
==>
Based on the information you shared - you have one (book) to many (book-authors) post relationship so you have many (book-authors).

To display many related post you will require view to display related post.

Here is the Doc that shows how you can display the many related items (if you are using blocks):
- https://toolset.com/course-lesson/displaying-related-posts/#displaying-many-related-items

If you are using classic view, then you should follow the following Doc:
- https://toolset.com/documentation/legacy-features/views-plugin/displaying-related-child-posts/

If you require further assistance please feel free to get in touch with me.

#2657049

Hi thanks for the reply. Sorry I said the wrong thing initially - the relationship is one author to many books.

I had read those docs before but couldn't figure out how to make it work. Both 'books' and 'book authors' have a post template they're using. I just want to use one field (not anything else) from 'book authors' on the 'book' post template. Can you give me an example of what the shortcode would look like to do that?

#2657225

Minesh
Supporter

Languages: English (English )

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

Ok.

If you want to display the single related parent, you should add a single field block and try to follow the following section:
=> https://toolset.com/course-lesson/displaying-related-posts/#displaying-one-related-item-parent

If you want to display it using Types shortcode:

[types field='custom-field-slug' item='@post-relationship-slug.parent']

Where:
- Replace 'custom-field-slug' with your original custom field slug
- Replace "post-relationship-slug" with your original post relationship slug

If you want to display parent post title then:

[wpv-post-title item="@post-relationship-slug.parent"]

Where:
- Replace "post-relationship-slug" with your original post relationship slug

To better understand how this "item" attribute works in Toolset shortcodes, this guide will help:
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

#2657523

Great that did it! How can change the shortcode so the output links to the parent post?

#2657597

Minesh
Supporter

Languages: English (English )

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

If you want to display the parent post link then you should try to use the following shortcode:

[wpv-post-link item="@post-relationship-slug.parent"]

Where:
- Replace "post-relationship-slug" with your original post relationship slug

More info:
- https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-link