[wp-trac] [WordPress Trac] #42209: register_taxonomy with a non-sequential array index of post_types causes /wp-json/wp/v2/taxonomies to return an object not an array

WordPress Trac noreply at wordpress.org
Fri Oct 13 15:51:30 UTC 2017


#42209: register_taxonomy with a non-sequential array index of post_types causes
/wp-json/wp/v2/taxonomies to return an object not an array
--------------------------+-----------------------------
 Reporter:  spectacula    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.8.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I logged this as an issue with Gutenberg yesterday but it seems the error
 if further up the chain.

 https://github.com/WordPress/gutenberg/issues/3009

 When using register_taxonomy for a taxonomy that is to be shown in REST
 and to more than one post type the post type array must be sequential and
 0 indexed otherwise the REST request will return an object for types
 rather than an array. This came to my attention as a plug-in had popped
 out an entry from the middle of an array of post_types and left the array
 with a gap in its sequence.

 == Simple test ==
 {{{
 https://{domain}/wp-json/wp/v2/taxonomies/taxonomy_name/
 }}}

 This returns an object in types
 {{{#!php
 <?php
 register_taxonomy(
     'taxonomy_name',
     array( 0 => 'post', 2 => 'page' ),
     array( 'show_in_rest' => true )
 );
 }}}

 This returns an array
 {{{#!php
 <?php
 register_taxonomy(
     'taxonomy_name',
     array( 0 => 'post', 1 => 'page' ),
     array( 'show_in_rest' => true )
 );
 }}}

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


More information about the wp-trac mailing list