コピペでどうぞ
<?php
$categories = get_the_category($post->ID);
$category_ID = array();
foreach($categories as $category):
array_push( $category_ID, $category -> cat_ID);
endforeach ;
$args = array(
'post__not_in' => array($post -> ID),//現在の記事を除く
'posts_per_page'=> 10,//件数指定
'category__in' => $category_ID,//現在の記事と同じカテゴリ
'orderby' => 'rand',//ランダムに記事を選ぶ
);
$query = new WP_Query($args);
if( $query -> have_posts() ):
while ($query -> have_posts()) :
$query -> the_post();
?>
<!--ループ-->
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('thumbnail'); ?><?php the_title(); ?></a>
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>