<?php $categories = get_the_category($post->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), 'showposts'=>5, // Posts a mostrar 'caller_get_posts'=>1 ); $original_query = $wp_query; $wp_query = null; $wp_query = new WP_Query( $args ); if ( have_posts() ) : ?> <h3>Posts Relacionados</h3><ul> <?php while ( have_posts() ) : the_post(); ?> <li><?php the_post_thumbnail( 'thumbnail' ); ?><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> <?php endwhile; echo '</ul>'; endif; $wp_query = null; $wp_query = $original_query; wp_reset_postdata(); ?>