post_type == 'product' ) { $is_product = true; $next_post = get_adjacent_post( 1, '', 0, 'product_cat' ); $prev_post = get_adjacent_post( 1, '', 1, 'product_cat' ); if ( ! empty( $next_post ) ) { $next_post = et_visible_product( $next_post->ID, 'next' ); } if ( ! empty( $prev_post ) ) { $prev_post = et_visible_product( $prev_post->ID, 'prev' ); } if (is_null($prev_post)){ $prev_post_id = ''; } else { if ( empty($prev_post) && !is_object(get_previous_post())) { $prev_post_id = ''; } else { $prev_post_id = empty( $prev_post ) ? get_previous_post()->ID : $prev_post->ID; } } if (is_null($next_post)){ $next_post_id = ''; } else { if ( empty($next_post) && !is_object(get_next_post())) { $next_post_id = ''; } else { $next_post_id = empty($next_post) ? get_next_post()->ID : $next_post->ID; } } if ( empty($next_post) || empty($prev_post)) { $post_id = $post->ID; // current post ID $product = wc_get_product($post_id); $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => '12', 'order' => 'ASC', 'orderby' => 'date', 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'term_id', //This is optional, as it defaults to 'term_id' 'terms' => $product->get_category_ids(), 'operator' => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'. ), array( 'taxonomy' => 'product_visibility', 'field' => 'slug', 'terms' => 'exclude-from-catalog', // Possibly 'exclude-from-search' too 'operator' => 'NOT IN' ), ) ); $products = new WP_Query($args); // get IDs of posts retrieved from get_posts $ids = array(); while ( $products->have_posts() ) : $products->the_post(); global $product; $ids[] = $product->get_ID(); endwhile; // get and echo previous and next post in the same category // $index = array_search( $post_id, $ids ); if ( ( count($ids) - 1 ) > 2 ) { if ( empty($prev_post) ) { // $prev_post = $prev_post_id = isset( $ids[ $index - 1 ] ) ? $ids[ $index - 1 ] : 0; $prev_post = $prev_post_id = end($ids); if ( !empty($prev_post)) { $prev_post = et_visible_product( $prev_post, 'prev' ); $prev_post_id = is_object($prev_post) ? $prev_post->ID : ''; } } if ( empty($next_post)) { //$next_post = $next_post_id = isset( $ids[ $index + 1 ] ) ? $ids[ $index + 1 ] : 0; $next_post = $next_post_id = $ids[0]; if ( !empty($next_post)) { $next_post = et_visible_product( $next_post, 'next' ); $next_post_id = is_object($next_post) ? $next_post->ID : ''; } } } } } else { $next_post = get_next_post(); $prev_post = get_previous_post(); if ($next_post){ $next_post_id = $next_post->ID; } if ($prev_post){ $prev_post_id = $prev_post->ID; } } if (class_exists('YITH_WCBM_Frontend')) { remove_filter( 'post_thumbnail_html', array( YITH_WCBM_Frontend(), 'show_badge_on_product' ), 999 ); } ?>