$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); // $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' => $cat_ids, // 'operator' => 'IN', // ) // ), // ) // ); 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')) ); $number_of_products = get_option('custom_related_products_crp_number', 3); $slider_state = get_option('custom_related_products_slider','enable'); if ('enable' !== $slider_state) { $number_of_products = class_exists('Custom_Related_Products') ? Custom_Related_Products::wt_get_device_type() : '3'; } $number_of_products = apply_filters('wt_related_products_number', $number_of_products); if ( $related_products || !empty($global_related_by) ) : ?>