WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

WC_REST_Posts_Controller::get_items() public WC 1.0

Get a collection of posts.

{} Это метод класса: WC_REST_Posts_Controller{}

Хуки из метода
Возвращает

WP_Error/WP_REST_Response.

Использование

$WC_REST_Posts_Controller = new WC_REST_Posts_Controller();
$WC_REST_Posts_Controller->get_items( $request );
$request(WP_REST_Request) (обязательный)
Full details about the request.

Код WC_REST_Posts_Controller::get_items() WC 4.7.1

<?php
public function get_items( $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['date_query'] = array();
	// Set before into date query. Date query must be specified as an array of an array.
	if ( isset( $request['before'] ) ) {
		$args['date_query'][0]['before'] = $request['before'];
	}

	// Set after into date query. Date query must be specified as an array of an array.
	if ( isset( $request['after'] ) ) {
		$args['date_query'][0]['after'] = $request['after'];
	}

	if ( 'wc/v1' === $this->namespace ) {
		if ( is_array( $request['filter'] ) ) {
			$args = array_merge( $args, $request['filter'] );
			unset( $args['filter'] );
		}
	}

	// 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}_query", $args, $request );
	$query_args = $this->prepare_items_query( $args, $request );

	$posts_query = new WP_Query();
	$query_result = $posts_query->query( $query_args );

	$posts = array();
	foreach ( $query_result as $post ) {
		if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
			continue;
		}

		$data = $this->prepare_item_for_response( $post, $request );
		$posts[] = $this->prepare_response_for_collection( $data );
	}

	$page = (int) $query_args['paged'];
	$total_posts = $posts_query->found_posts;

	if ( $total_posts < 1 ) {
		// Out-of-bounds, run the query again without LIMIT for total count.
		unset( $query_args['paged'] );
		$count_query = new WP_Query();
		$count_query->query( $query_args );
		$total_posts = $count_query->found_posts;
	}

	$max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] );

	$response = rest_ensure_response( $posts );
	$response->header( 'X-WP-Total', (int) $total_posts );
	$response->header( 'X-WP-TotalPages', (int) $max_pages );

	$request_params = $request->get_query_params();
	if ( ! empty( $request_params['filter'] ) ) {
		// Normalize the pagination params.
		unset( $request_params['filter']['posts_per_page'] );
		unset( $request_params['filter']['paged'] );
	}
	$base = add_query_arg( $request_params, rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ) );

	if ( $page > 1 ) {
		$prev_page = $page - 1;
		if ( $prev_page > $max_pages ) {
			$prev_page = $max_pages;
		}
		$prev_link = add_query_arg( 'page', $prev_page, $base );
		$response->link_header( 'prev', $prev_link );
	}
	if ( $max_pages > $page ) {
		$next_page = $page + 1;
		$next_link = add_query_arg( 'page', $next_page, $base );
		$response->link_header( 'next', $next_link );
	}

	return $response;
}