WC_REST_Posts_Controller::prepare_items_query()protectedWC 1.0

Determine the allowed query_vars for a get_items() response and prepare for WP_Query.

Method of the class: WC_REST_Posts_Controller{}

Hooks from the method

Return

Array. $query_args

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_items_query( $prepared_args, $request );
$prepared_args(array)
Prepared arguments.
Default: array()
$request(WP_REST_Request)
Request object.
Default: null

WC_REST_Posts_Controller::prepare_items_query() code WC 9.5.1

protected function prepare_items_query( $prepared_args = array(), $request = null ) {

	$valid_vars = array_flip( $this->get_allowed_query_vars() );
	$query_args = array();
	foreach ( $valid_vars as $var => $index ) {
		if ( isset( $prepared_args[ $var ] ) ) {
			/**
			 * Filter the query_vars used in `get_items` for the constructed query.
			 *
			 * The dynamic portion of the hook name, $var, refers to the query_var key.
			 *
			 * @param mixed $prepared_args[ $var ] The query_var value.
			 */
			$query_args[ $var ] = apply_filters( "woocommerce_rest_query_var-{$var}", $prepared_args[ $var ] );
		}
	}

	$query_args['ignore_sticky_posts'] = true;

	if ( 'include' === $query_args['orderby'] ) {
		$query_args['orderby'] = 'post__in';
	} elseif ( 'id' === $query_args['orderby'] ) {
		$query_args['orderby'] = 'ID'; // ID must be capitalized.
	} elseif ( 'slug' === $query_args['orderby'] ) {
		$query_args['orderby'] = 'name';
	}

	return $query_args;
}