[wp-trac] [WordPress Trac] #29899: wp_insert_term should return an object instead of an array

WordPress Trac noreply at wordpress.org
Thu Oct 9 09:18:52 UTC 2014


#29899: wp_insert_term should return an object instead of an array
-------------------------+-----------------------------
 Reporter:  andyexeter   |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Taxonomy     |    Version:  4.0
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 When using `wp_insert_term()` I believe the return value should be an
 object like  `get_term()` and `get_term_by()`

 The rationale behind this can be summarized in this code snippet:


 {{{
 $term = get_term_by('name', 'my-term', 'my-taxonomy');

 if($term) {
   $term_id = $term->term_id;
 } else {
   $term = wp_insert_term('my-term', 'my-taxonomy');

   $term_id = $term['term_id'];
 }
 }}}

 If `wp_insert_term()` returned an object that code could be simplified to:

 {{{
 $term = get_term_by('name', 'my-term', 'my-taxonomy');

 if(!$term) {
   $term = wp_insert_term('my-term', 'my-taxonomy');
 }

 $term_id = $term->term_id;
 }}}

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


More information about the wp-trac mailing list