如果我理解正确的话,这本书和评论有着相同的分类法。
那么,只需在single-books.php
, 将其保存在变量中,然后使用该变量为\'tax_query\'
:
if ( have_posts() ) {
the_post();
// get the term for the current book and save in a variable
$book_terms = get_the_terms( get_the_ID(), \'your_custom_taxonomy\' );
$book_term = ! empty( $book_terms ) ? array_shift( $book_terms ) : FALSE;
// loop code for the book goes here
}
if ( $book_term ) { // if we get the term for current book...
// second query
$args = array(
\'post_type\' => \'review\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'your_custom_taxonomy\',
\'terms\' => array( $book_term->term_id )
)
)
);
$reviews = new WP_Query( $args );
// loop code for review goes here
}