$cat_value) { $all_ids = get_posts( array( 'post_type' => 'product', 'numberposts' => -1, 'post_status' => 'publish', 'fields' => 'ids', 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', 'terms' => array($cat_value), 'operator' => 'IN', ) ), ) ); $total = array_merge($total,$all_ids); unset($all_ids); } } $all_ids = array_unique($total); return $all_ids; } } if ( ! function_exists( 'crp_get_all_product_ids_from_tag_ids' ) ) { /** * Get all product ids from the given tag ids * @since 1.3.7 * @return array */ function crp_get_all_product_ids_from_tag_ids( array $tag_ids ) { $all_ids = get_posts( array( 'post_type' => 'product', 'numberposts' => -1, 'post_status' => 'publish', 'fields' => 'ids', 'tax_query' => array( array( 'taxonomy' => 'product_tag', 'field' => 'term_id', 'terms' => $tag_ids, 'operator' => 'IN', ) ), ) ); return $all_ids; } } if ( ! function_exists( 'crp_get_all_product_ids_from_attr_ids' ) ) { /** * Get all product ids from the given attributes * @since 1.4.0 * @return array */ function crp_get_all_product_ids_from_attr_ids( array $attr_data ) { $tax_query = array( 'relation'=> 'OR' ); foreach ($attr_data as $attr_name => $attr_term_ids) { $tax_query[] = array( 'taxonomy' => "pa_$attr_name", 'terms' => $attr_term_ids, 'operator' => 'IN', ); } $all_ids = new WP_Query( array( 'post_type' => array('product', 'product_variation'), 'posts_per_page' => -1, 'post_status' => 'publish', 'fields' => 'ids', 'tax_query' => $tax_query ) ); if( $all_ids->have_posts() ) { return $all_ids->posts; } return array(); } } $global_related_by = (array) apply_filters( 'wt_crp_global_related_by', get_option('custom_related_products_crp_related_by', array('category')) ); if ( @$related_products || !empty($global_related_by) ) : ?>