Share code

Get post by current custom taxonomy in singple custom postye

HƯỚNG DẪN LẤY BÀI VIẾT TRONG TRANG DANH MỤC – CUSTOM POSTYPE

 

<?php
global $post;
$terms = wp_get_post_terms( $post->ID, 'danh-muc-khoa-hoc',array('fields' => 'ids') );
$args = array(
  'post_type' => 'khoa-hoc',
  'tax_query' => array(
    array(
      'taxonomy' => 'danh-muc-khoa-hoc',
      'field' => 'term_id',
      'terms' => $terms
    )
  ),
  'post__not_in' => array( $post->ID ),
);

$my_query = new WP_Query( $args );
if($my_query->have_posts()) :
while ($my_query->have_posts()) : $my_query->the_post(); ?>

  <?php endwhile;
endif;
?>