启动循环时,需要引用查询,否则它将显示通过主查询找到的帖子,而不是自定义查询。
尝试:
<?php
$args = array( \'post_type\'=>\'book\');
$loop = new WP_Query( $args );
// Start the loop for your custom query
if($loop->have_posts() ) : while ($loop->have_posts() ) : $loop->the_post();
the_title(); // just an example, output what you need here
// Get the post terms
$term_list = wp_get_post_terms($post->ID, \'best-book\', array("fields" => "all"));
// Iterate the terms, if found
if($term_list) {
foreach($term_list as $term_single) {
echo $term_single;
}
}
endwhile;
// In case the query is empty
else:
// Debug the query
echo \'<pre>\';
var_dump($loop);
echo \'</pre>\';
endif;
?>