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.

The following has a custom post type of features, within that a custom tax called feature-type with three categories, template-1, template-2 and template-3.

Each custom post feature needs to select one of the templates and then show any children based on that query...

So create a post assign a template category add x number of child posts for the parent post assigned the original category.

Using the custom function for conditional taxonomies 'has_template' so if a post has this template show all its child posts..

I cobbled together this, not fully understanding conditionals. Shows the posts fine, its when i added the child query within the conditional that it messes up and only shows the last one..

<?php query_posts( array( 'post_type' => 'feature','orderby' =>'ASC','post_parent' => 0)) ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

 <?php if ( has_template( 'template-1' ) ) { ?>

     <?php query_posts( array( 'post_type' => 'feature','posts_per_page' => '-1','post_parent' => $post->ID) ); ?>
           <ul>
           <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
           <li>
          <?php the_title(); ?>
          </li>
       <?php endwhile; endif; wp_reset_query();?>

   </ul>

<?php } elseif ( has_template( 'template-2' ) ) { ?>

        <?php query_posts( array( 'post_type' => 'feature','posts_per_page' => '-1','post_parent' => $post->ID) ); ?>
           <ul>
           <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
           <li>
          <?php the_title(); ?>
          </li>
       <?php endwhile; endif; wp_reset_query();?>

   </ul>

 <?php } elseif ( has_template( 'template-3' ) ) { ?>  

        <?php query_posts( array( 'post_type' => 'feature','posts_per_page' => '-1','post_parent' => $post->ID) ); ?>
           <ul>
           <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
    <li>
     <?php the_title(); ?>
    </li>
  <?php endwhile; endif; wp_reset_query();?>

</ul>

   <?php } else { ?>
   <?php } ?>

<?php endwhile; endif; wp_reset_query();?>     
<!--end custom post type query-->  
share|improve this question
    
Please fix your indentation and make this code readable without scrolling. 4 whitespaces will suffice. –  Johannes Pille Apr 5 '13 at 9:33
    
don't use query_posts. change your parent a child queries to instead use new instances of WP_Query and update your question with the new code if you still have issues. –  Milo Apr 5 '13 at 15:38

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.