Skip to content

Instantly share code, notes, and snippets.

@hafizrahman
Last active December 5, 2019 04:56
Show Gist options
  • Save hafizrahman/04265e530b2823792fa53c802a4894f2 to your computer and use it in GitHub Desktop.
Save hafizrahman/04265e530b2823792fa53c802a4894f2 to your computer and use it in GitHub Desktop.
Add WP REST API support to certain taxonomies
/**
* Add REST API support to an already registered taxonomy.
*/
add_filter( 'register_taxonomy_args', 'my_taxonomy_args', 10, 2 );
function my_taxonomy_args( $args, $taxonomy_name ) {
if ( 'freebbble-type' === $taxonomy_name || 'freebbble-license' === $taxonomy_name ) {
$args['show_in_rest'] = true;
// Optionally customize the rest_base or rest_controller_class
$args['rest_controller_class'] = 'WP_REST_Terms_Controller';
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment