Automattic\WooCommerce\Blocks\BlockTypes

ProductQuery::merge_queries()privateWC 1.0

Merge in the first parameter the keys "post_in", "meta_query" and "tax_query" of the second parameter.

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

Хуков нет.

Возвращает

Массив.

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

// private - только в коде основоного (родительского) класса
$result = $this->merge_queries( ...$queries );
...$queries(array[]) (обязательный)
Query arrays to be merged.

Код ProductQuery::merge_queries() WC 7.3.0

private function merge_queries( ...$queries ) {
	$merged_query = array_reduce(
		$queries,
		function( $acc, $query ) {
			if ( ! is_array( $query ) ) {
				return $acc;
			}
			// If the $query doesn't contain any valid query keys, we unpack/spread it then merge.
			if ( empty( array_intersect( $this->get_valid_query_vars(), array_keys( $query ) ) ) ) {
				return $this->merge_queries( $acc, ...array_values( $query ) );
			}
			return $this->array_merge_recursive_replace_non_array_properties( $acc, $query );
		},
		array()
	);

	/**
	 * If there are duplicated items in post__in, it means that we need to
	 * use the intersection of the results, which in this case, are the
	 * duplicated items.
	 */
	if (
		! empty( $merged_query['post__in'] ) &&
		count( $merged_query['post__in'] ) > count( array_unique( $merged_query['post__in'] ) )
	) {
		$merged_query['post__in'] = array_unique(
			array_diff(
				$merged_query['post__in'],
				array_unique( $merged_query['post__in'] )
			)
		);
	}

	return $merged_query;
}