Skip to content

Instantly share code, notes, and snippets.

@dboutote
Last active June 14, 2022 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dboutote/2f6cd014f8df60018abc3f3aedea934a to your computer and use it in GitHub Desktop.
Save dboutote/2f6cd014f8df60018abc3f3aedea934a to your computer and use it in GitHub Desktop.
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