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

WordPress Trac noreply at wordpress.org
Sun Aug 20 17:15:21 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        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Wordpress fails to report the (custom) categories a post is in.

 {{{
 $terms = get_the_terms( $post->ID, 'project_category' );
 }}}

 returns no results.

 {{{
 $terms = wp_get_object_terms( $post->ID, 'project_category' );
 }}}

 does, which I believe to be correct.

 I have traced the problem back to:

 class-wp-term-query.php.

 The caching code that calls this relies on object_ids (all_with_object_id)
 to come back, but the object_ids are eaten by:
 {{{
      if ( 'all' === $_fields || 'all_with_object_id' === $_fields) {
                         $terms = array_map( 'get_term', $terms );
                 }
 }}}

 commenting out the {{{'all_with_object_id' === $_fields}}} part yields
 correct results. But I am not sure that is the correct fix. presumably
 having a WP_Term object come back in this case had some intention?

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


More information about the wp-trac mailing list