WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Custom Post Type called glossary. I set up parent posts called "A", "B", etc. The glossary terms themselves are then set with the appropriate initial as their parent post. So, for example, "abdomen" has the "A" post set as its parent and "protein-skimmer" has the "P" post as its parent.

I now have a list of these initials,

<a href="/glossary/a/">A</a>
<a href="/glossary/b/">B</a>

When clicking on these links, I'm taken to a view which displays the individual "A" or "B" post.

What I'd like to see instead is "A" as a header, then a list of all of its children posts.

What's the most effective way to do this?

Thanks in advance,

share|improve this question
up vote 1 down vote accepted

Try this, it's the most basic implementation. It could be more effecient to hook into pre_get_posts, and change the query from a 'top level page' to a query for it's children. But that has the potential to break a few things, and in particular would probably require you to alter the template used.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();  ?>

    <header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header><!-- .entry-header -->

    <?php   //If top level, find children
        if($post->post_parent == 0):
            $children = new WP_Query(array(

            if($children->have_posts()): ?>
                <?php while ( $children->have_posts() ) : $children->the_post(); ?>
                    <li> <?php the_title();?> </li>
                <?php endwhile; ?>

            <?php else: ?>
                <?php echo 'No children';?>
            <?php endif; ?>

            <?php wp_reset_postdata(); ?>
        <?php else://Not top level, display normal post ?>
            <?php the_content(); ?>
        <?php endif;?>

    <?php endwhile; // end of the loop. ?>
<?php endif; ?>
share|improve this answer

Your Answer


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

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