rest_prepare_(post_type)
Filters the post data for a REST API response.
The dynamic portion of the hook name, $this->post_type, refers to the post type slug.
Possible hook names include:
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 $post Post object. * @param WP_REST_Request $request Request object. * * @return WP_REST_Response */ function wp_kama_rest_prepare_post_type_filter( $response, $post, $request ){ // filter... return $response; }
- $response(WP_REST_Response)
- The response object.
- $post(WP_Post)
- Post object.
- $request(WP_REST_Request)
- Request object.
Changelog
Since 4.7.0 | Introduced. |
Where the hook is called
rest_prepare_(post_type)
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2046
return apply_filters( "rest_prepare_{$this->post_type}", $response, $post, $request );
Where the hook is used in WordPress
wp-includes/blocks/navigation.php 1689
add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
wp-includes/default-filters.php 764
add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 );