[wp-trac] [WordPress Trac] #17646: wp_get_object_terms should return arrays of integers for IDs and tt_IDs

WordPress Trac wp-trac at lists.automattic.com
Thu Jun 2 02:26:35 UTC 2011


#17646: wp_get_object_terms should return arrays of integers for IDs and tt_IDs
---------------------------+------------------------------
 Reporter:  simonwheatley  |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Taxonomy       |     Version:  3.2
 Severity:  normal         |  Resolution:
 Keywords:  needs-patch    |
---------------------------+------------------------------

Comment (by dd32):

 > attachment 17646.diff  added
  * Not a clean patch, Just a diff showing my thinking
  * Utilises sanitize_term() / sanitize_term_field() for sanitizing values,
 ie. int'ing fields
  * causes get_term(), get_term_by(), wp_get_object_terms() and most other
 high level taxonomy functions to return int'd values as expected (no point
 fixing one function and leaving the rest) - There are other tickets for
 these I believe.

 Other functions that don't int the results:
  * get_objects_in_term() - object_id
  * class WP_Tax_Query - Doesn't int term_ids, or sanitize them in any way,
 just returns the table results into WP_Query
  * term_exists() - term_id, term_taxonomy_id as strings
  * wp_set_object_terms() term_taxonomy_ids as strings

 Example output:

 {{{
 $res = get_term(1, 'category');
 var_dump($res);

 object(stdClass)[648]
   public 'term_id' => int 1
   public 'name' => string 'Uncategorized' (length=13)
   public 'slug' => string 'uncategorized' (length=13)
   public 'term_group' => int 0
   public 'term_taxonomy_id' => int 1
   public 'taxonomy' => string 'category' (length=8)
   public 'description' => string '' (length=0)
   public 'parent' => int 0
   public 'count' => int 6
   public 'filter' => string 'raw' (length=3)

 $term_ids = wp_get_object_terms( 1, 'category', array( 'fields' => 'ids' )
 );
 var_dump( $term_ids );

 array
   0 => int 1
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17646#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list