[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
Thu Sep 20 10:05:28 UTC 2018


#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:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  REST API                  |     Version:  4.8.2
 Severity:  normal                    |  Resolution:
 Keywords:  has-unit-tests has-patch  |     Focuses:
--------------------------------------+------------------------------

Comment (by spectacula):

 I've run into this again today and was surprised to see it not fixed. A
 client wanted a certain taxonomy removed from a custom post type. This
 causes REST calls to the taxonomy to throw the wrong data type for
 **types**.
 The taxonomy and post type are created by a plugin that's outside of our
 control so we'd rather not have to modify it and thus have to maintain it.
 The change isn't one that'd need to be fed back to the original plugin
 authors either as it's not a bug just a client preference.

 Here's an example that achieves the same effect:

 {{{#!php
 <?php
 add_action( 'init', function() {
     register_taxonomy(
         'taxonomy_name',
         array( 'post', 'attachment', 'page' ),
         array( 'show_in_rest' => true )
     );

     unregister_taxonomy_for_object_type( 'taxonomy_name', 'attachment' );
 } );

 // Make request to https://{domain}/wp-
 json/wp/v2/taxonomies/taxonomy_name/
 // "types":{"0":"post","2":"page"} instead of "types":["post","page"]
 }}}

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


More information about the wp-trac mailing list