[wp-trac] [WordPress Trac] #5780: get_terms returns empty array for parameter fields=names

WordPress Trac wp-trac at lists.automattic.com
Wed Feb 6 17:19:56 GMT 2008


#5780: get_terms returns empty array for parameter fields=names
----------------------+-----------------------------------------------------
 Reporter:  Sarky-de  |       Owner:  anonymous
     Type:  defect    |      Status:  new      
 Priority:  normal    |   Milestone:  2.6      
Component:  General   |     Version:  2.3.2    
 Severity:  normal    |    Keywords:  has-patch
----------------------+-----------------------------------------------------
 The function call

 {{{
 get_terms('post_tag', 'fields=names')
 }}}

 is expected to return an array containing all tag names. An empty array is
 returned instead.

 {{{
 get_terms('post_tag', 'fields=ids')
 }}}

 returns an array with all tag IDs as expected.

 This error is the result of wrong operator and a missing if-condition in
 taxonomy.php:

 Current code (starting from line 572:
 {{{
         else if ( 'names' == $fields )
                 $select_this == 't.name';

         $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN
 $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN
 ($in_taxonomies) $where ORDER BY $orderby $order $number";

         if ( 'all' == $fields ) {
                 $terms = $wpdb->get_results($query);
                 update_term_cache($terms);
         } else if ( 'ids' == $fields ) {
                 $terms = $wpdb->get_col($query);
         }
 }}}

 Fixed code:
 {{{
         else if ( 'names' == $fields )
                 $select_this = 't.name';

         $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN
 $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN
 ($in_taxonomies) $where ORDER BY $orderby $order $number";

         if ( 'all' == $fields ) {
                 $terms = $wpdb->get_results($query);
                 update_term_cache($terms);
         } else if ( ('ids' == $fields) || ('names' == $fields) ) {
                 $terms = $wpdb->get_col($query);
         }
 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/5780>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list