Πως δημιουργούμε σχετικά άρθρα στο WordPress

function tcp_related_posts() {
	
	global $post, $wpdb;
	$backup = $post;  
	$tags = wp_get_post_tags($post->ID);
	$tagIDs = array();
	if ($tags) {
	  $tagcount = count($tags);
	  for ($i = 0; $i < $tagcount; $i++) {
	    $tagIDs[$i] = $tags[$i]->term_id;
	  }
	  $tagIDs = array_diff($tagIDs, array(364, 365, 556));
	  $showposts = get_theme_mod('related_postnum');
	  $showposts = !empty($showposts) ? $showposts : 5;
	  
	  $args=array(
	    'tag__in' => $tagIDs,
	    'post__not_in' => array($post->ID),
		'cat'=> '-5',
	    'showposts'=>$showposts,
	    'caller_get_posts'=>1
	  );
	  $my_query = new WP_Query($args);
	  if( $my_query->have_posts() ) { $related_post_found = true; ?>
		<h3>Σχετικά άρθρα</h3>
	    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> 
				<a class="title" href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail('bloview');?><br><?php the_title(); ?></a>
	    <?php endwhile; ?>
	  <?php }
	}
	
	if(!$related_post_found){ ?>
		<h3>'Δημοφιλή άρθρα</h3>
		<ul>
		<?php
		$posts = get_posts('numberposts='.$showposts.'&offset=0&cat=-5&orderby=rand');
		foreach($posts as $post) { ?>
				<a class="title" href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail('bloview');?><br><?php the_title(); ?></a>
		<?php } ?>
		</ul>
		
		<?php 
	}
	wp_reset_query();
}