[wp-trac] [WordPress Trac] #39089: Setting the Object Relationship Between Post Type Objects and Taxonomy Objects

WordPress Trac noreply at wordpress.org
Mon Dec 5 17:34:58 UTC 2016


#39089: Setting the Object Relationship Between Post Type Objects and Taxonomy
Objects
-------------------------------+-----------------------------
 Reporter:  michael.ecklund    |      Owner:
     Type:  enhancement        |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  4.6.1
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 '''Does it matter which is object is created first when setting the object
 relationship between Post Type Objects and Taxonomy Objects?'''

 ----------

 > Are you supposed to register Post Types **FIRST**, and Taxonomies
 required by that Post Type **SECOND**?

 OR

 > Are you supposed to register the Taxonomies **FIRST**, and the Post
 Types which use those Taxonomies **SECOND**?

 ----------

 **The way I look at it is:**

 Taxonomy Objects should be created first before the Post Type Objects,
 since they're ultimately the bond between Post Objects and Post Type
 Objects; Taxonomies can be used across multiple Post Types objects.

 The reason I ask this is: because the WordPress Codex seems to outline it
 as register the Post Types FIRSTLY, and then register the Taxonomies
 SECONDLY.

 **I get this vibe by looking at two functions in the WordPress Codex:**

  1.
 [`register_post_type();`](https://codex.wordpress.org/Function_Reference/register_post_type#Arguments)
 - If you look at the arguments section, there's an argument for Taxonomies
 (**Notice:** This is ''plural'').
  2.
 [`register_taxonomy();`](https://codex.wordpress.org/Function_Reference/register_taxonomy#Parameters)
 - If you look at the parameters section, there's an parameter for
 specifying a single Object Type or Multiple Object Types. However, the
 actual parameter is called `$object_type`. (**Notice:** this is
 ''singular'').

 Now, where I'm confused is: PHP loads things in a procedural order. So
 there for one event needs to happen before the next. Both of the above
 functions have the capability of specifying multiple object types as a
 relationship.

 So to conclude my final question. What makes the most sense? Register Post
 Types first and Taxonomies second, or visa-versa?

 I also ask this because when you are dealing with the Post Type Objects
 and Taxonomy Objects in a programmatic way. Each object has a property
 which contains an array of related objects.

 Look at
 [`get_post_type_object();`](https://codex.wordpress.org/Function_Reference/get_post_type_object#Examples)
 and
 [`get_taxonomy();`](https://codex.wordpress.org/Function_Reference/get_taxonomy#Examples)

 It's kind of misleading having one object say there's no relationship.
 Then have the other object say there definitely is a relationship.

 So for my own sanity and keeping things consistent, I've been creating my
 Taxonomies first and Post Types second.

 I set the parameter (`$object_type`) to `null` in `register_taxonomy();`
 and then I specify the desired Taxonomies in the Taxonomies argument when
 using `register_post_type();`.

 I then follow up with my consistency of using:
 [`register_taxonomy_for_object_type( $taxonomy, $object_type
 );`](https://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type)

 That way, the relationship is clear when dealing with either object.

 Could this happen automatically? So that no matter which object you're
 dealing with, upon inspection, the relationship is clear.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39089>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list