WC_REST_CRUD_Controller::prepare_objects_query()
Prepare objects query.
Метод класса: WC_REST_CRUD_Controller{}
Хуки из метода
Возвращает
Массив
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->prepare_objects_query( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Список изменений
С версии 3.0.0 | Введена. |
Код WC_REST_CRUD_Controller::prepare_objects_query() WC REST CRUD Controller::prepare objects query WC 9.3.3
protected function prepare_objects_query( $request ) { $args = array(); $args['offset'] = $request['offset']; $args['order'] = $request['order']; $args['orderby'] = $request['orderby']; $args['paged'] = $request['page']; $args['post__in'] = $request['include']; $args['post__not_in'] = $request['exclude']; $args['posts_per_page'] = $request['per_page']; $args['name'] = $request['slug']; $args['post_parent__in'] = $request['parent']; $args['post_parent__not_in'] = $request['parent_exclude']; $args['s'] = $request['search']; $args['fields'] = $this->get_fields_for_response( $request ); if ( 'date' === $args['orderby'] ) { $args['orderby'] = 'date ID'; } $date_query = array(); $use_gmt = $request['dates_are_gmt']; if ( isset( $request['before'] ) ) { $date_query[] = array( 'column' => $use_gmt ? 'post_date_gmt' : 'post_date', 'before' => $request['before'], ); } if ( isset( $request['after'] ) ) { $date_query[] = array( 'column' => $use_gmt ? 'post_date_gmt' : 'post_date', 'after' => $request['after'], ); } if ( isset( $request['modified_before'] ) ) { $date_query[] = array( 'column' => $use_gmt ? 'post_modified_gmt' : 'post_modified', 'before' => $request['modified_before'], ); } if ( isset( $request['modified_after'] ) ) { $date_query[] = array( 'column' => $use_gmt ? 'post_modified_gmt' : 'post_modified', 'after' => $request['modified_after'], ); } if ( ! empty( $date_query ) ) { $date_query['relation'] = 'AND'; $args['date_query'] = $date_query; } // Force the post_type argument, since it's not a user input variable. $args['post_type'] = $this->post_type; /** * Filter the query arguments for a request. * * Enables adding extra arguments or setting defaults for a post * collection request. * * @param array $args Key value array of query var to query value. * @param WP_REST_Request $request The request used. */ $args = apply_filters( "woocommerce_rest_{$this->post_type}_object_query", $args, $request ); return $this->prepare_items_query( $args, $request ); }