Automattic\WooCommerce\Blocks\BlockTypes

RelatedProducts::build_query()publicWC 1.0

Return a custom query based on attributes, filters and global WP_Query.

Метод класса: RelatedProducts{}

Хуков нет.

Возвращает

Массив.

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

$RelatedProducts = new RelatedProducts();
$RelatedProducts->build_query( $query );
$query(WP_Query) (обязательный)
The WordPress Query.

Код RelatedProducts::build_query() WC 9.1.2

public function build_query( $query ) {
	$parsed_block = $this->parsed_block;
	if ( ! $this->is_related_products_block( $parsed_block ) ) {
		return $query;
	}

	$related_products_ids = $this->get_related_products_ids( $query['posts_per_page'] );
	if ( count( $related_products_ids ) < 1 ) {
		return array();
	}

	return array(
		'post_type'      => 'product',
		'post__in'       => $related_products_ids,
		'post_status'    => 'publish',
		'posts_per_page' => $query['posts_per_page'],
	);
}