[wp-trac] [WordPress Trac] #37686: Add object_type column to term_relationships table

WordPress Trac noreply at wordpress.org
Wed Aug 17 11:32:42 UTC 2016


#37686: Add object_type column to term_relationships table
-----------------------------+------------------------------
 Reporter:  johnjamesjacoby  |       Owner:
     Type:  enhancement      |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Taxonomy         |     Version:
 Severity:  normal           |  Resolution:
 Keywords:  2nd-opinion      |     Focuses:
-----------------------------+------------------------------

Comment (by dd32):

 > This means that a taxonomy term ID cannot be used for both post ID's and
 user ID's, as there is no way to know if an object_id is for a post ID or
 a user ID.

 Just to clarify on this, currently we tie taxonomies to an `$object_type`
 which although is normally thought of as `post_type`  nothing prevents you
 from using `'users'` as the post type. What you cannot do however, is have
 `$object_type` be an array of multiple differently indexed types (so not
 `[ 'user', 'post' ]`, or `[ 'user', 'option' ]`).

 > This means that a taxonomy term ID cannot be used for both post ID's and
 user ID's, as there is no way to know if an object_id is for a post ID or
 a user ID.
 This isn't an issue going forward, as now that we have split terms, each
 taxonomy (which still, IMHO, should only be added to a single collection
 of uniquely id'd terms) will get it's own term_taxonomy_id. It shouldn't
 really be possible to have the ID of `TermA` in a posts taxonomy also
 assigned to a user in another taxonomy, nor should they be sharing the
 same taxonomy name IMHO..

 ----

 This sort of functionality has been on the radar, and has always been, as
 part of the [https://make.wordpress.org/core/2013/07/28/potential-roadmap-
 for-taxonomy-meta-and-post-relationships/ Taxonomy Roadmap] work (Scroll
 down to the final references to `wp_term_relationships`) but was never
 fully ironed out as what to do there, as we've had a long amount of
 simplifying to do to get to where we are today.

 I'm not 100% sold that the solution here should be to switch from a single
 unique ID `(object_id) => term_id` to a tuple of `(object_type, object_id)
 => term_id` though. As outlined in the above link, a more powerful useful
 implementation may be to convert to a object linking table of
 `(object_type, object_id) => (object_type, object_id)` which would allow
 far more flexibility in how it's used, and also prevent hacky solutions
 like using a taxonomy as a middleman to link two pieces of content
 together.
 At first, it seems that implementing just `(object_type, object_id) =>
 term_id` is a step in the right direction, and that it could then be
 upgraded/iterated on later to add the object_type to the right side of the
 equation, however I feel that it would needlessly complicate matters and
 muddy the upgrade paths going forward.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37686#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list