dimanche 30 novembre 2014

List Terms by category


I have a custom taxonomy called "portfolio-type". The terms = post_type is "portfolio" and category is "portfolio-type"


I'm trying to fetch related post of the same category of current post



<?php
global $post;
$terms = get_the_terms( $post_id, 'portfolio-type' );
$terms = $terms[0]->cat_ID;
$myposts = get_posts(array('numberposts' => 5, 'offset' => 0, 'post_type' =>'portfolio', 'category__in' => wp_get_post_categories( $post_id, 'portfolio-type' ), 'post__not_in' => array($post->ID), 'post_status'=>'publish', 'order'=>'ASC' ));
foreach($myposts as $post) :
setup_postdata($post);
?>

<?php endforeach; ?>
<?php wp_reset_query(); ?>


The script shows related posts however doesn't show current post. I'm using this code for showing related posts as a sidebar menu.


Any advice?





Aucun commentaire:

Enregistrer un commentaire