[wp-trac] [WordPress Trac] #45232: get_object_term_cache() returns an empty array

WordPress Trac noreply at wordpress.org
Tue Oct 30 19:21:26 UTC 2018


#45232: get_object_term_cache() returns an empty array
----------------------------+-----------------------------
 Reporter:  sebastienserre  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Post Formats    |    Version:  5.0
 Severity:  normal          |   Keywords:  dev-feedback
  Focuses:                  |
----------------------------+-----------------------------
 Hello
 I'm in a case where get_object_term_cache() in get_the_terms() returns an
 empty array evenif I have term (as post_format) for the posts.

 in
 {{{
         $terms = get_object_term_cache( $post->ID, $taxonomy );
         if ( false === $terms ) {
                 $terms = wp_get_object_terms( $post->ID, $taxonomy );
                 if ( ! is_wp_error( $terms ) ) {
                         $term_ids = wp_list_pluck( $terms, 'term_id' );
                         wp_cache_add( $post->ID, $term_ids, $taxonomy .
 '_relationships' );
                 }
         }
 }}}

 checking if  $terms is also empty solves the problem.
 if you think it's a "bug" I'll create the patch.

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


More information about the wp-trac mailing list