Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Filtering the WP REST API endpoints.
<?php
add_action( 'rest_endpoints', function( $endpoints ){
if( isset( $endpoints[ '/wp/v2/posts' ] ) ){
foreach( $endpoints[ '/wp/v2/posts' ] as &$post_endpoint ){
if( ! empty( $post_endpoint[ 'methods' ] ) && 'GET' == $post_endpoint[ 'methods' ] ){
$post_endpoint[ 'args' ][ 'type' ] = array(
'description' => 'Post types',
'type' => 'array',
'required' => false,
'default' => 'post'
);
}
}
}
return $endpoints;
}, 15 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment