[wp-trac] [WordPress Trac] #41293: wp_get_post_terms do not work with 'id=>name' argument

WordPress Trac noreply at wordpress.org
Wed Jul 12 07:56:33 UTC 2017


#41293: wp_get_post_terms do not work with 'id=>name' argument
--------------------------+-----------------------------
 Reporter:  dany2217      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.7.5
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi, i'm not sure is that really bug, let me explain it.
 When i used code below it doesn't worked for me.

 {{{#!php
 <?php
 $terms = wp_get_post_terms($post_id, $taxonomy, array(
 'fields' => 'id=>name',
 ));

 // returns
 // array(0 => 'term name 1', 1 => 'term name 2')
 }}}

 The term ID is just an index of array, so i tried to find the reason.
 After trace the core code i found the problem in wp_get_object_terms
 function.

 {{{#!php
 <?php
 $terms = array_merge( $terms, get_terms( $args ) );
 }}}

 When $terms array was merged, the term ID ( array keys ) were reindexed.
 I don't know what logic is the best in this situation, but the array_merge
 function is not right method i think.

 {{{#!php
 <?php
 // maybe something like this ?
 $terms = $terms + get_terms( $args );
 }}}

 My english is poor, so take a look for code at first.

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


More information about the wp-trac mailing list