Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
QueryBuilder::merge_post__in()
Merge all of the 'post__in' values and return an array containing only values that are present in all arrays.
Method of the class: QueryBuilder{}
No Hooks.
Return
Int[]
. The merged 'post__in' values.
Usage
// private - for code of main (parent) class only $result = $this->merge_post__in( ...$post__in );
- ...$post__in(int[][]) (required)
- The 'post__in' values to be merged.
QueryBuilder::merge_post__in() QueryBuilder::merge post in code WC 9.6.0
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 ) ); }