Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 20th, 2012  |  syntax: None  |  size: 0.50 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Related Post
  2. function get_related_posts($post_id, $tags = array()) {
  3.         $query = new WP_Query();
  4.        
  5.         $post_types = get_post_types();
  6.         unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']);
  7.        
  8.         if($tags) {
  9.                 foreach($tags as $tag) {
  10.                         $tagsA[] = $tag->term_id;
  11.                 }
  12.         }
  13.         $query = new WP_Query( array('showposts' => 4,'post_type' => $post_types,'post__not_in' => array($post_id),'tag__in' => $tagsA,'ignore_sticky_posts' => 1,
  14.         ));
  15.         return $query;
  16. }
clone this paste RAW Paste Data