[Resuelto] Created Related Posts within Same Post Type
This support ticket is created hace 3 años, 3 meses. 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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
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)
Este tema contiene 6 respuestas, tiene 3 mensajes.
I'm trying to link one post to several other posts, but both the "post relationship" and "reference post" options do not allow you to link one post to another if they are in the same post type. Can you please recommend the best way to do this?
To add detail, some posts may have other posts that we want to reference. For example, if there is a part 1 (free) and part 2 (premium) post, we want to reference the counterpart. Similarly, if there is prerequisite reading we want them to do prior to reading a post, we want to call that out.
There isn't any support for self-joins currently, and there isn't really a good solution to propose.
You would need something like a custom field to store the id of the related post, meaning you would have to edit both posts and provide the id of the other post in that custom field.
Then in the template for the posts you could output the title of (or a link to) the related post using a shortcode, where you use the item attribute to point to the linked post as the source, providing the value from the custom field, something like:
That part is easy enough, it is connecting the posts that is awkward, because you need to know the IDs of the posts to connect, not a very user-friendly experience.
You could store the post title instead, and then create a custom shortcode to use in place of wpv-post-field in the above example which retrieved the post ID from the post title, but that would still involve manually entering the title (rather than selecting it) and so would be prone to error.
Do you think the following "less than perfect" solution would work?
1) Create a post type called "References"
2) Create a many-to-many relationship between References and Posts
3) Create a Reference that is linked to both Posts (i.e. Post A is linked to Reference 1, but Reference 1 is linked to Post A and Post B)
Can you tell me if the following "less than perfect" solution would work?
1) Create a post type called References
2) Create a many-to-many relationship between References and Posts
3) Link Post A to Reference 1, with Reference 1 being linked to Post A and Post B
Do you see this as being a feature Toolset would consider adding?
I do think it would be a valuable feature. It has been suggested before but our developers have not yet decided to implement it. If you'd like to express your desire to add this feature, feel free to submit a feature request here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Can you tell me if the following "less than perfect" solution would work?
Technically, it is possible to implement something like this. However, it is somewhat difficult to manage in wp-admin. From Post 1, you could add a relationship to an existing Reference 1 post, or create a Reference 1 post and automatically link it to Post 1. But you could not add links to Post 2 and Post 3 directly from Post 1, you would have to do that from the Reference 1 post, or from the Post 2 or Post 3 posts. It's even more difficult to manage with front-end Forms, especially if that Reference post does not already exist. It also makes displaying lists of related posts difficult because this type of filtering isn't easily accomplished in the Block Editor.
Nigel's solution is viable, as is a custom taxonomy solution. Instead of a true post relationship, apply the same taxonomy term to each pair or group of "related" Posts. Either a taxonomy-based approach or a custom field approach will make displaying lists of "related" posts more straightforward, not requiring nested Views or shortcode / custom code solutions.
I suggest setting up a sandbox site or a test environment so you can try out each approach to see the pros and cons of each possible solution. You can create a free account in our sandbox environment at https://discover-wp.com if you don't have an easily accessible test environment. We can collaborate there if you'd like.