diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 26477634ea581..9eff6ecbeb67a 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -772,8 +772,4 @@ add_filter( 'rest_prepare_wp_block', 'insert_hooked_blocks_into_rest_response', 10, 2 ); add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 ); -// Filter the pages endpoint to consider orderby_hierarchy. -add_filter( 'rest_page_query', 'rest_page_query_hierarchical_sort_filter_by_post_in', 10, 2 ); -add_filter( 'rest_prepare_page', 'rest_prepare_page_hierarchical_sort_add_levels', 10, 3 ); - unset( $filter, $action ); diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 9750789d11a85..9cbbb08836134 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -402,6 +402,8 @@ static function ( $format ) { // Force the post_type argument, since it's not a user input variable. $args['post_type'] = $this->post_type; + $args = rest_page_query_hierarchical_sort_filter_by_post_in( $args, $request ); + /** * Filters WP_Query arguments when querying posts via the REST API. * @@ -2090,6 +2092,8 @@ public function prepare_item_for_response( $item, $request ) { } } + $response = rest_prepare_page_hierarchical_sort_add_levels( $response, $post, $request ); + /** * Filters the post data for a REST API response. *