Skip Navigation

[Resolved] Link to related posts in same post type

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

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

Problem: I would like to create a list of posts that are related to the current post. The posts are all in the same post type.

Solution: In the current system, the best way to do this is to use a custom taxonomy that includes terms that match the slugs of each post. For example, you have Post A and Post B that should be related to each other. So you create terms "post-a" and "post-b" in a custom taxonomy. Then you add the term "post-b" to Post A, and you add the term "post-a" to Post B.
Then create a View of this post type, filtered by taxonomy term slug, where the slug is set by a shortcode attribute "wpv-related-posts". In the Loop Output of this View, insert a post link with the wpv-post-link shortcode.
Pass the current page's slug into this shortcode attribute using the wpv-post-slug shortcode, like this:

[wpv-view name="your-view-slug" wpv-related-posts="[wpv-post-slug id='$current_page']"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-slug
https://toolset.com/documentation/user-guides/create-custom-taxonomies/

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#614716

hello,

I have a post type artist and would like to link other artists in this type. how can I fill a field by displaying a pulldown list with all artist, is there an easy example to do this. would be nice to see something like the ID and the Name saved in the field.
regards

#615001

Hi, there is not currently a built-in way to select other posts from the same post type like this in custom field values. The best way to do something similar is to use a custom Taxonomy to relate posts. In your new Taxonomy, create a term that matches the slug of the current post, and assign that term to any post you want to see on the current post as a related post link. For example, let's say you have Post A and Post B, whose slugs are "post-a" and "post-b". You want to show Post B as a related post link on Post A, and vice versa. Let's assume your custom Taxonomy is called "Related-Posts". Edit Post A and add the term "post-b". Edit Post B and add the term "post-a".

Next, create a new View of this post type, filtered by Related-Post taxonomy term slug, set by a shortcode attribute like "wpv-related-post". Insert this View in your Content Template or Template Layout for this Post type using a shortcode. Pass the current post's slug into the wpv-related-posts filter like this:

[wpv-view name="your-view-slug" wpv-related-posts="[wpv-post-slug id='$current_page']"]

Now your View will show all the posts related to the current post. This relationship is not automatically reciprocal, so you must relate Post A to Post B, and also relate Post B to Post A, in order for the links to appear on both posts.

The forum ‘Types Community Support’ is closed to new topics and replies.