Skip to content

Instantly share code, notes, and snippets.

@rodrigo-brito
Last active August 29, 2015 14:20
Show Gist options
  • Save rodrigo-brito/2a23b6712aea9a984213 to your computer and use it in GitHub Desktop.
Save rodrigo-brito/2a23b6712aea9a984213 to your computer and use it in GitHub Desktop.
Related post - Custom taxonomy and Custom post type
<div class="related-posts">
<?php
$terms = get_the_terms( $post->ID , 'genero'); //genero é a taxonomia que criei aqui
if ( $terms && ! is_wp_error( $terms ) ) {
$slugs = array();
foreach ( $terms as $term ) {
$slugs[] = $term->term_id;
}
}
$args = array(
'post_type' =>'filme',
'tax_query' => array(
array(
'taxonomy' => 'genero',
'terms' => $slugs,
),
),
'showposts' => 5,
'caller_get_posts' => 1,
'post__not_in' => array($post->ID)
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '<h3>Related Posts</h3><ul>';
while ($my_query->have_posts()) {
$my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php }
echo '</ul>';
} ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment