1

I have registered a custom post type "Projects" and also registered a custom taxonomy for that Post Type called "Project Categories". On my home page I have a div in which I would like to list all projects and terms fro the "Project Categories" taxonomy. Currently, I am only able to get the lists of the terms. Can someone tell me why I am unable to get the terms to display. Currently, I have:

<div class="list-container">
    <?php 
    query_posts( array( 'post_type' => 'projects' ) );
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; endif; wp_reset_query(); ?>
    <?php $taxonomy = 'project_categories';
    $tax_terms = get_terms($taxonomy);
                            ?>
    <?php foreach ($tax_terms as $cat): ?>
        <li><?php $cat; ?></li>
    <?php endforeach; ?>
</div><!--end list-container-->

Another question I have is, is it better to include the taxonomies inside or outside of the query_posts loop?

0

You'e not echoing out $cat in your foreach loop in the code you provided.

Change : <li><?php $cat; ?></li> to <li><?php echo $cat; ?></li>

Edit:

get_terms() returns an array of objects. So if you want to display the name of the term in your foreach loop it would be:

<li><?php echo $cat->name; ?></li>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.