Вывести похожие записи WordPress

<?php
$categories = get_the_category($post->ID);
if ($categories) :
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
    'category__in' => $category_ids,
    'post__not_in' => array($post->ID),
    'showposts' => '3',
    'orderby' => 'rand',
    'ignore_sticky_posts' => '1',
    'no_found_rows' => true,
    'cache_results' => false
);
$my_query = new wp_query($args);
if( $my_query->have_posts() ) : ?>                   
<div class="sample-posts">
    <div class="container">
        <div class="title-block">Похожие статьи</div>
        <div class="sample_block">
            <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <a class="news--inner_sample" href="">
                <div class="miniature">
                    <?php
                    $autoimage = wpschool_first_post_img();
                    if( has_post_thumbnail() ) {
                        the_post_thumbnail('large');
                    }
                    else {
                        echo '<img src="' . $autoimage . '" alt="" />';
                    }?>
                </div>
                <div class="title">
                    <h2><?php the_title(); ?></h2>
                </div>
                <div class="descr">
                    <p><?php echo trim_characters(180, '...'); ?></p>
                </div>
                <div class="btn-block">
                    <span class="btn" href="<?php the_permalink(); ?>">Читать далее</span>
                </div>
            </a>
            <?php endwhile; ?>
        </div>
    </div>
</div>
<?php endif; wp_reset_query(); endif; ?>

Вывести похожие записи из пользовательской таксономии из той категории, где находится эта запись

<?php
if (is_singular('products')) {
    $current_product_id = get_the_ID();
    $product_categories = wp_get_post_terms($current_product_id, 'productscat', array('fields' => 'ids'));

    $args = array(
        'post_type' => 'products',
        'posts_per_page' => 10,
        'post__not_in' => array($current_product_id),
        'tax_query' => array(
            array(
                'taxonomy' => 'productscat',
                'field' => 'id',
                'terms' => $product_categories
            )
        )
    );

    $related_products_query = new WP_Query($args);

    if ($related_products_query->have_posts()) {
?>
<div class="products-recomendation">
    <div class="container">
        <div class="content-title">Так же советуем обратить внимание</div>
    </div>
    <div class="slider-cont">
        <div class="product-recomendation-slider swiper">
            <div class="swiper-wrapper">
                <?php
                while ($related_products_query->have_posts()) {
                $related_products_query->the_post(); ?>  
                <div class="swiper-slide">
                    <a class="product-item" href="<?php the_permalink(); ?>">
                        <div class="miniature">
                            <img src="<?php the_post_thumbnail_url('medium_large'); ?>" alt="">
                        </div>
                        <div class="text">
                            <div class="title-block"><?php the_title();?></div>
                            <div class="descr"><p><?php the_content(); ?></p></div>
                            <div class="price"><?php the_field('новая_цена'); ?></div>
                        </div>
                        <span class="btn"><span>Подробнее</span></span>
                    </a>
                </div>
                <?php } ?>
            </div>
        </div>
        <div class="slider-nav-item slider-prev"></div>
        <div class="slider-nav-item slider-next"></div>
    </div>
</div>
<?php } wp_reset_postdata(); } ?>
Контакты

Работаем: с ПН по ПТ, с 08:00 до 17:00 (МСК)
Отдыхаем: в СБ и ВС, чтобы быть в тонусе
и реализовывать самые сложные идеи