Skip Navigation

[Resolved] Connecting custom posts to a custom post of the same type

This support ticket is created 4 years, 6 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
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)

This topic contains 2 replies, has 2 voices.

Last updated by davidR-12 4 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1359691

I want to connect a custom post type (Topics) to other topics so that when a topic displays there is a related topic area that will display with the connected topics. I cant do this with relationships as this doesnt work with the same post types (odd). How do I do this?

Regards,

David

#1359721

Hi, we expect to include the ability to relate posts in the same post type with Post Relationships in an upcoming version of the software, and now that Gutenberg/Blocks integration is close to full release we expect that to be happening soon after that. Until that improvement, it's not possible to use relationships between posts of the same post type, and it's also not possible to relate the same two posts more than once in a many-to-many relationship. The best way to associate posts in the same post type right now is to use a custom, flat taxonomy

The custom flat taxonomy approach can work in different ways. Obviously there is the categorization aspect you can use to link similar posts using terms relevant to the post content (all posts about "weather", for example). That's often not enough, and you need the ability to arbitrarily associate multiple posts, like a "Related posts" list. In a custom Taxonomy, create a term that is identical the slug of each 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 in a list of related posts on Post A, and you want to show Post A in a list of related posts on Post B. 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". That's all you need to do to set the association between the posts.

Next, you want to display a list of related posts on each post's single post template. Create a new View of this post type, filtered by Related-Post taxonomy term slug, set by a shortcode attribute like "wpvrelatedposts". 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" wpvrelatedposts="[wpv-post-slug id='$current_page']"]

Now your View will show all the posts that include the term whose slug is identical to the slug of 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. So it's twice as much work as setting a post relationship, but there is an autosuggest field you can use to search for terms (i.e. other posts) when editing a post to set up these relationships. That makes it easier to maintain than the next solution.

The other approach is to use a repeating numeric custom field to add related post IDs to each post. This is even more difficult to manage because there is no autosuggest input, and you would have to know each post ID you want to associate with the post you are editing. Your View would be a View of posts fltered by post IDs instead of terms.

#1362607

Hi Christian,

I find this to be a very strange omission. I switched the project to ACF which provides this functionality.

Regards,

David

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