views:

22

answers:

1

I am using a custom post type in my wordpress theme, and I need help with the loop. Here is my code:

<?php $loop = new WP_Query( array( 'post_type' => 'magazine', 'posts_per_page' => 10 ) ); ?>
     <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
         <li>
             <?php the_post_thumbnail( 'magazine' ); ?>
             <h2><?php the_title( ); ?></h2>
             <?php the_content;?>
         </li>
     <?php endwhile; ?>

This returns the 10 latest posts in the custom field "magazine". I want it to only display the parents in the custom field "magazine". Just like pages, my custom fields have attributes, so you can select a hierarchy (parent/child). I want to edit the loop so it only returns the parents (the latest issues of the magazine, not the articles within each issue) Does anyone know how to do that using the wordpress loop above?

A: 

Just add 'post_parent' => 0 to the args array.

<?php $loop = new WP_Query( array( 'post_type' => 'magazine', 'posts_per_page' => 10, 'post_parent' => 0 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
     <li>
         <?php the_post_thumbnail( 'magazine' ); ?>
         <h2><?php the_title( ); ?></h2>
         <?php the_content;?>
     </li>
<?php endwhile; ?>
John P Bloch
what about just the opposite, if you just want the children?
JCHASE11
That's quite a bit more difficult. You could add a custom WHERE statement checking if the post_parent field is greater than 0, but other than that I can't think of anything.
John P Bloch
Do you want ALL child posts to ALL parent posts, or just the children of a single post?
kevtrout