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 ), 'posts_per_page' => $related_count, // Number of related posts that will be shown. 'ignore_sticky_posts' => 1 ); } } //Related Posts By Tags else { $tags = wp_get_post_tags( $post->ID ); if ( $tags ) { $tag_ids = array(); foreach( $tags as $individual_tag ) $tag_ids[] = $individual_tag->term_id; $args = array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => $related_count, // Number of related posts to display. 'ignore_sticky_posts' => 1 ); } } if ($categories || $tags) { $my_query = new WP_Query( $args ); if( $my_query->have_posts() ) { ?>