2, 'post__not_in' => array( get_the_ID() ), 'ignore_sticky_posts' => true ); $current_post_categories = get_the_category(get_the_ID()); if( $current_post_categories ) : foreach( $current_post_categories as $current_post_cat ) : $query_cats[] = $current_post_cat->term_id; endforeach; $related_posts_args['category__in'] = $query_cats; endif; $related_posts = new WP_Query( $related_posts_args ); if( ! $related_posts->have_posts() ) return; ?>