Skip to content

Instantly share code, notes, and snippets.

@MxAshUp
Last active November 10, 2017 01:39
Show Gist options
  • Save MxAshUp/bac1da32c2d6c66c3b453f30f8dba7c7 to your computer and use it in GitHub Desktop.
Save MxAshUp/bac1da32c2d6c66c3b453f30f8dba7c7 to your computer and use it in GitHub Desktop.
<?php
class WP_REST_Posts_Controller_StringTerms extends WP_REST_Posts_Controller {
/**
* Retrieves the post's schema, conforming to JSON Schema.
*
* @return array Item schema data.
*/
public function get_item_schema() {
$schema = parent::get_item_schema();
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
foreach ( $taxonomies as $taxonomy ) {
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
if(!array_key_exists( $base, $schema['properties'] )) {
continue;
}
$schema['properties'][ $base ][ 'items' ][ 'type'] = 'string';
}
return $schema;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment