Maintaining strict one-to-one association between terms and custom posts

I’m building an inventory system where inventory items have their own page but where standard WordPress post post types can also be tagged with these inventory items. As far as I understand, this means I must implement both a custom post type (inventory) to provide each item’s page and a custom, non-hierarchical taxonomy (inventory_item) to represent the relationships between posts in the post post type and pages in the inventory post type. Each custom post type post would be associated with exactly one inventory_item term.

Assuming that the above is the best approach to accomplish this sort of relationship, then this implies that I must handle various edge cases to guarantee the custom-post-to-term relationship is maintained. For example:

When an inventory post is edited or deleted, the corresponding inventory_item term must be updated/deleted too.
It should not be possible for users to create or edit inventory_item terms on their own, for example via the term edit page or editor term metabox / Gutenberg widget. These should only be created when a corresponding inventory custom post type post is created.
Should I create the term when the custom post type post is published, or merely drafted? What about when a post is trashed but not fully deleted – when should I delete the terms and associations?
How do I get the inventory_item terms to take the user to the corresponding custom post when the link is clicked (for example in a tag cloud)?

Clearly, maintaining this strict one-to-one relationship will require many hooks to handle the various ways in which it can be disrupted. I’d like to hear thoughts about whether this approach seems like the best one to implement what I need, and whether anyone knows of a plugin that implements this already that I could take a look at.

Read more here:: Maintaining strict one-to-one association between terms and custom posts

Leave a Reply

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