0
votes

I have a custom post type called recipe and custom taxonomies called cuisine and recipe_type.

I want to show the list of 10 recipes on a page and the associated term of the taxonomies it belongs to:

I have the following code which shows the recipes but not that taxonomy terms:

<?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;?>
1
Is $query->post->ID even bringing back anything? I don't think that's a valid variable based on the code you pasted. Either way, step-through debugging would be very useful.Nic

1 Answers

0
votes

Following code worked to display the taxonomy term related to the custom post type

<?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>