I am trying to create and enforce such a relationship between custom_post_types.
parent_chlid

Question:
How to ‘link’ the post_types in a manner that allows finding parent/child of any post_type?

Examples:
Querying for parent of ‘barter’ should give classified_post_type .
Querying for leaf nodes of user_post_type gives all the leaf nodes. etc

I understand this cannot be achieved just by creating custom_post_types. But is there any way like taxonomy/metafield to link different custom post types together ? Actually I am not bent on using customn_post_types. Just want the above mentioned behaviour, if possible.

ty

3 s
3

I would suggest you create a common hierarchical taxonomy that you register with each of your custom post types.

The terms of this taxonomy would match your custom post types (for example use the custom post type slug as the term slug).

You can then structure your taxonomy to match your designed hierarchy, and every time you need to find the parent/child you refer back to the taxonomy.

You could have a parent_post and a child_post meta fields to store the post IDs of the respective parent and child post.

Leave a Reply

Your email address will not be published. Required fields are marked *