Last active
June 14, 2022 16:47
-
-
Save dboutote/2f6cd014f8df60018abc3f3aedea934a to your computer and use it in GitHub Desktop.
Filtering the WP REST API endpoints.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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