[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 21:02:06 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        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by birgire):

 Welcome to trac and thanks for the ticket.

 We can reproduce this with:

 {{{
 // output: {"0":"post","2":"page"}
 $json = wp_json_encode( array( 0 => 'post', 2 => 'page' ) );

 // output: ["post","page"]
 $json = wp_json_encode( array( 0 => 'post', 1 => 'page' ) );

 }}}

 where  {{{wp_json_encode()}}} is a wrapper of {{{json_encode()}}}.

 This seems to be an expected behavior for {{{json_encode()}}}.

 So you're suggesting to re-index it, to ensure the array output?

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


More information about the wp-trac mailing list