[wp-trac] [WordPress Trac] #41679: get_the_terms does not return expected results

WordPress Trac noreply at wordpress.org
Tue Aug 29 00:13:46 UTC 2017


#41679: get_the_terms does not return expected results
-------------------------------+------------------------------
 Reporter:  rslotb             |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Taxonomy           |     Version:  4.8.1
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Comment (by boonebgorges):

 @rslotb Thanks a lot for the detailed explanation. I think we are getting
 closer to the root of the issue.

 In the general case, `object_id` *is* set on `WP_Term` objects returned
 from `wp_get_object_terms()`. There are a number of tests that verify
 this, at least indirectly. See eg
 https://core.trac.wordpress.org/browser/tags/4.8.1/tests/phpunit/tests/term/wpGetObjectTerms.php?marks=704#L690.
 Also, if this were not generally the case, much of WordPress would break
 :) So something more specific is going on here.

 It's not totally obvious how this works, so here's a quick rundown.
 Hopefully this will help you to go back and debug which part of the chain
 is failing in your case.

 1. When querying for terms using `all_with_object_id`, the `tr.object_id`
 field is part of the database query.
 https://core.trac.wordpress.org/browser/tags/4.8.1/src/wp-includes/class-
 wp-term-query.php?marks=593-595#L586 The resulting objects thus have
 `object_id` set.
 2. These objects are then run through `get_term()`.
 https://core.trac.wordpress.org/browser/tags/4.8.1/src/wp-includes/class-
 wp-term-query.php?marks=813-815#L811 (so far this matches what you've
 reported)
 3. A `stdClass` object (the result of the database query) passed to
 `get_term()` will hit this conditional
 https://core.trac.wordpress.org/browser/tags/4.8.1/src/wp-
 includes/taxonomy.php?marks=735-738#L724, which results in the database
 object being passed to `WP_Term::__construct()`
 4. The `WP_Term` object is then set up with each property of the
 `__construct()` payload.
 https://core.trac.wordpress.org/browser/tags/4.8.1/src/wp-includes/class-
 wp-term.php?marks=205-207#L196 This includes `object_id`, so that
 `$term->object_id` is set as the `object_id` property on the `WP_Term`
 object.

 My guess is that one of the filters in `get_term()` has a callback that's
 stripping the `object_id` property.
 https://core.trac.wordpress.org/browser/tags/4.8.1/src/wp-
 includes/taxonomy.php?marks=761,775#L752 Check before and after these
 filters.

 If that's not it, maybe you can do some more detailed debugging to see
 exactly where in steps 1-4 the `object_id` param is not being properly
 passed along.

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


More information about the wp-trac mailing list