Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection

QueryBuilder::merge_post__inprivateWC 1.0

Merge all of the 'post__in' values and return an array containing only values that are present in all arrays.

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

Хуков нет.

Возвращает

int[]. The merged 'post__in' values.

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

// private - только в коде основоного (родительского) класса
$result = $this->merge_post__in( ...$post__in );
...$post__in(int[][]) (обязательный)
The 'post__in' values to be merged.

Код QueryBuilder::merge_post__in() WC 9.9.4

private function merge_post__in( ...$post__in ) {
	if ( empty( $post__in ) ) {
		return array();
	}

	// Since we're using array_intersect, any array that is empty will result
	// in an empty output array. To avoid this we need to make sure every
	// argument is a non-empty array.
	$post__in = array_filter(
		$post__in,
		function ( $val ) {
			return is_array( $val ) && ! empty( $val );
		}
	);
	if ( empty( $post__in ) ) {
		return array();
	}

	// Since the 'post__in' filter is exclusionary we need to use an intersection of
	// all of the arrays. This ensures one query doesn't add options that another
	// has otherwise excluded from the results.
	if ( count( $post__in ) > 1 ) {
		$post__in = array_intersect( ...$post__in );
		// An empty array means that there was no overlap between the filters and so
		// the query should return no results.
		if ( empty( $post__in ) ) {
			return array( -1 );
		}
	} else {
		$post__in = reset( $post__in );
	}

	return array_values( array_unique( $post__in, SORT_NUMERIC ) );
}