【发布时间】:2014-12-29 17:16:55
【问题描述】:
我有一个名为 recipe 的自定义帖子类型和名为 cuisine 和 recipe_type 的自定义分类。
我想在一个页面上显示 10 个食谱的列表以及它所属的分类法的相关术语:
我有以下代码显示食谱但不显示分类术语:
<?php
query_posts(array(
'post_type' => 'recipe',
'showposts' => 10
) );
?>
<?php while (have_posts()) : the_post(); ?>
<li>
<?php the_title(); ?>
<?php $terms = wp_get_post_terms( $query->post->ID, array( 'cuisine', 'recipe_type' ) ); ?>
<?php foreach ( $terms as $term ) : ?>
<p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p>
<?php endforeach; ?>
</li>
<?php endwhile;?>
【问题讨论】:
-
$query->post->ID还能带回什么东西吗?根据您粘贴的代码,我认为这不是一个有效的变量。无论哪种方式,逐步调试都会非常有用。