The following displays a parent term in a custom taxonomy, then displays the child terms and finally is intended to display the post links (custom posts) for the posts attached to each term. Thus:

  • Child 1
    • Post 1.1
    • Post 1.2
  • Child 2
    • Post 2.1

However, the query is returning no posts. I'd appreciate any pointers as to the source of the problem. For the sake of brevity I've omitted the set up list of variables that precedes this code.

echo("<h3 class='chapter-header'id='".$chapterNumber."'>". $chapter_info->name . "</h3>");
echo("<div class='section' id=".$in_chapter.">"); // Start sections Div.
    foreach ($sections as $section){
                echo("<h3 class='section-header'>". $section->name."</h3>");// Display Section Name
    $postqueryargs = array(
            'taxonomy'=> $taxonomy, 
            'terms'=> $section->slug                                        
    $pagequery = new WP_Query($postqueryargs);
    echo("<div class='pages'>");// Start pages div
            while ($pagequery->have_posts()):$pagequery->the_post();
                echo('<li><a href=" '.get_permalink().'" rel="bookmark" title="Permanent Link to '. get_the_title().'"  >' .get_the_title() . '</a></li>'); 
        echo("No Pages Yet In This Chapter");

      echo("</div>");/* End pages */
          }// End foreach - Sections
echo("</div>");/* End section */

1 Answer 1


The way you query for Taxonomy is deprecated, see the reference in the Codex: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

So instead of

'taxonomy'=> $taxonomy, 

you should use this:

'tax_query' => array(
            'taxonomy' => $taxonomy,
            'field' => 'slug',
            'terms' => $section->slug 

And make sure that $taxonomy is defined!

  • Thx. I'd been switching back and forth between tax_query and a single array but couldn't get it to work with either approach. It appears the addition of "field"-> 'slug' was the missing piece.
    – dorich
    Commented Sep 4, 2013 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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