$post_terms = wp_get_object_terms($post->ID, 'ten_category', array('fields'=>'ids')); $post_id = $post->ID; $args = array( 'post_type' => 'post', 'tax_query' => array( array( 'taxonomy' => 'ten_category', 'field' => 'id', 'terms' => $post_terms, 'post__not_in' => array($post->ID) ) ) ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); if(get_the_ID() != $post_id) { // -- Code hiển thị bài viết -- // } } } else { console.log("No related posts found."); } wp_reset_postdata();
Gắn code sau vào đâu bạn muốn hiển thị trong single.php
Bạn thay từ : ten_category để hiển thị đúng chuyên mục nhé.
Chúc các bạn thành công !