Skip Navigation

[Resolved] Custom Field of reference to other Post Type.

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

Problem: I would like to use a custom field to store a relationship to a post in another post type.

Solution: In the current system, you can use a one-to-many or many-to-many relationship to relate two posts from different post types. Or you can use a custom field to store the post ID of another post. You can also use a custom taxonomy to relate two posts. In the new betas we are revamping this to make post references must more straightforward.

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

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

Assisted by: Christian Cox.

Author
Posts
#625964

Hey there,
I've created 2 custom post types.
1. Laureate
2. Competitor

In Laureate CPT, I want to add a custom field, of a reference to a Competitor.

What's the proper way to do that?

#626003

In the current system, you can use a "number" custom field to store the post ID of another post, or you can use a post relationship to establish a one-to-many or many-to-many relationship between two posts in different post types. It is also possible to use a custom taxonomy to relate posts in different post types. The post ID field is a great, simple solution but it requires you to know the post ID of the related post because it is not possible to search by post name in this type of input field. The post relationship is a good option because you can search for the post title easily to add a relationship, but many-to-many relationship filters are somewhat limited in Views compared to custom field and taxonomy term filters. The taxonomy term solution involves creating a term that matches the slug of each post, then you can use that term to associate the post with other posts. For example, if you have CPT 1 and CPT 2, you can create terms "cpt-1" and "cpt-2", then assign "cpt-2" to the CPT 1 post, and assign "cpt-1" to the CPT 2 post. Then you can use these terms as query filters to show related posts in a View. This is somewhat more tedious, but a very flexible solution.

In the new beta plugins, we are revamping the way post relationships are stored and represented, so the post relationship option will become more straightforward. Views will be updated as well to create more robust filtering options that support post relationships. Unfortunately I do not have a timeline for the final release of these features, and we release new beta versions quite frequently. The best place to keep up with those releases is in our blog: https://toolset.com/blog

#626164

If I set a post relationship between 'Laureate' & 'Competitor',
Will it have any affect on my current views?
Will I have to change anything in them in order to preserve the current situation?

The whole idea is needed in order to create a link for a 'Competitor' page, from a 'Laureate' view.

#626260

Will it have any affect on my current views?
If you currently have a View on your site that queries these post types using post relationships, then the results of this View may change when you add the post relationship. But existing Views that do not test post relationships should not be affected in a noticeable way.

Will I have to change anything in them in order to preserve the current situation?
If you currently have a View that queries these post types using post relationships, then the results of that View may change. I do not know how to change these Views to preserve the current situation, it would require more investigation.