WP_REST_Posts_Controller::prepare_items_query( array $prepared_args = array(), WP_REST_Request $request = null ): array
- Since
- 4.7.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:1215
Determines the allowed query_vars for a get_items() response and prepares them for WP_Query.
Parameters
$prepared_argsarrayoptional- Prepared WP_Query arguments. Default empty array.Default:
array() $requestWP_REST_Requestoptional- Full details about the request.Default:
null
Return
array- Items query arguments.
Hooks fired · 1
One hook fires while WP_REST_Posts_Controller::prepare_items_query() runs, in this order:
- apply_filters( rest_query_var-{$key} )filterline 1231 (+16 into the body)
Filters the query_vars used in get_items() for the constructed query.
Uses · 1
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 3
- WP_REST_Attachments_Controller::prepare_items_query()Determines the allowed query_vars for a get_items() response and prepares for WP_Query.
- WP_REST_Menu_Items_Controller::prepare_items_query()Determines the allowed query_vars for a get_items() response and prepares them for WP_Query.
- WP_REST_Posts_Controller::get_items()Retrieves a collection of posts.
Source
protected function prepare_items_query( $prepared_args = array(), $request = null ) { $query_args = array(); if ( ! is_array( $prepared_args ) ) { $prepared_args = array(); } foreach ( $prepared_args as $key => $value ) { /** * Filters the query_vars used in get_items() for the constructed query. * * The dynamic portion of the hook name, `$key`, refers to the query_var key. * * @since 4.7.0 * * @param string $value The query_var value. */ $query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } if ( 'post' !== $this->post_type || ! isset( $query_args['ignore_sticky_posts'] ) ) { $query_args['ignore_sticky_posts'] = true; } // Map to proper WP_Query orderby param. if ( isset( $query_args['orderby'] ) && isset( $request['orderby'] ) ) { $orderby_mappings = array( 'id' => 'ID', 'include' => 'post__in', 'slug' => 'post_name', 'include_slugs' => 'post_name__in', ); if ( isset( $orderby_mappings[ $request['orderby'] ] ) ) { $query_args['orderby'] = $orderby_mappings[ $request['orderby'] ]; } } return $query_args; }History
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.