Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got three products (called "Kits") and each kit contains several items. The "items" are a custom post type which are linked to each kit via a relationship field. Each item has a custom taxonomy attached to it ("departments"). The departments have no direct link to the products (or "kits"), except via the items.

When I display the products, I want to loop through each term found in "departments". Then, have a nested <ul> that lists each item that is found in the current department AND in the current product.

I've got the department names print out in a <ul> which is perfect. But then I'm trying to query the CPT "item" and loop through the posts associated with the current "department". When I print_r the items, it says that I'm in the right department, but returns no data about the items.

Any idea how I can actually access the title of the item custom post type?

Also, this is a link to the array that's being returned by print_r($items)

<div class="items" id="details<?php the_ID(); ?>">  
    <?php $departments = get_terms( 'departments', 'orderby=count&hide_empty=0' ); ?>
            <?php foreach ($departments as $department): ?>
                <?php $dept = ($department->name) ?>
                <?php echo $dept ?>
                <?php $args = array(
                    'post_type' => 'item',
                    'tax_query' => array(
                            'taxonomy' => 'departments',
                            'terms' => $dept
                <?php $items = new WP_Query( $args ); ?>
                    echo "<pre>";
                    echo "</pre>";?>
                <?php while ( $items->have_posts() ) : $items->the_post(); ?>
                    <li><?php the_title(); ?></li>
                  <?php endwhile; ?>
            <?php endforeach ?>
share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.