// Related Post function get_related_posts($post_id, $tags = array()) { $query = new WP_Query(); $post_types = get_post_types(); unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']); if($tags) { foreach($tags as $tag) { $tagsA[] = $tag->term_id; } } $query = new WP_Query( array('showposts' => 4,'post_type' => $post_types,'post__not_in' => array($post_id),'tag__in' => $tagsA,'ignore_sticky_posts' => 1, )); return $query; }