<?php
$terms = get_the_terms($post->ID, 'カスタムタクソノミーのスラッグ名');
foreach( $terms as $term ) {
$slug = $term->slug
}
?>
<?php
$arg = array(
'post_type' => 'カスタム投稿タイプのスラッグ',
'posts_per_page' => 4,
'orderby' => 'rand',
'post__not_in' => array($post->ID),
'tax_query' => array(
array(
'taxonomy' => 'カスタムタクソノミーのスラッグ',
'field' => 'slug',
'terms' => $slug
)
)
);
$wp_query = new WP_Query($arg);
?>
<?php if( $wp_query->have_posts() ): ?>
<?php while( $wp_query->have_posts() ): ?>
<?php $wp_query->the_post(); ?>
--- 繰り返し処理 ---
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>