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), 'showposts' => 4, // these are the number of related posts we want to display 'ignore_sticky_posts' => 1 // to exclude the sticky post ); // WP_Query takes the same arguments as query_posts $related_query = new WP_Query($args); if ($related_query->have_posts()) { ?>