2014-12-29 255 views
0

我有一个自定义帖子类型称为recipe和自定义分类标准为cuisinerecipe_type显示自定义帖子类型分类术语旁边帖子在Wordpress

我要显示的页面与分类的相关术语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;?> 
+0

的分类项是'$查询 - > POS t-> ID'甚至可以带回任何东西?我不认为这是基于您粘贴的代码的有效变量。无论哪种方式,逐步调试将非常有用。 – Nic

回答

0

以下代码工作,以显示与自定义后类型

<?php 
query_posts(array( 
'post_type' => 'recipe', 

'showposts' => 10 
)); 
?> 

<?php while (have_posts()) : the_post(); ?> 
<li> 
<?php the_title(); ?> 
<?php $terms = get_the_terms($post->ID , 'recipe_type'); ?> 

<?php foreach ($terms as $term) : ?> 
<p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p> 
<?php endforeach; ?> 

</li> 
相关问题