rest_prepare_post_type
Filters a post type returned from the REST API.
Allows modification of the post type data right before it is returned.
Usage
add_filter( 'rest_prepare_post_type', 'wp_kama_rest_prepare_post_type_filter', 10, 3 ); /** * Function for `rest_prepare_post_type` filter-hook. * * @param WP_REST_Response $response The response object. * @param WP_Post_Type $post_type The original post type object. * @param WP_REST_Request $request Request used to generate the response. * * @return WP_REST_Response */ function wp_kama_rest_prepare_post_type_filter( $response, $post_type, $request ){ // filter... return $response; }
- $response(WP_REST_Response)
- The response object.
- $post_type(WP_Post_Type)
- The original post type object.
- $request(WP_REST_Request)
- Request used to generate the response.
Changelog
Since 4.7.0 | Introduced. |
Where the hook is called
rest_prepare_post_type
wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php 279
return apply_filters( 'rest_prepare_post_type', $response, $post_type, $request );