WordPress WP_Query - How to show just post parent?

1

Good night everyone, I have a CPT where each post has its child, when listing this with WP_Query, the page shows all the posts (father and son), however I want to show only the 'parent' posts, like Can I do this?

Thank you very much!

follow the code used:

 <!-- primeiro Loop -->
      <?php
       $args = array(
           'post_type' => 'novellist'                
       );
       $novels = new WP_Query( $args );

       if( $novels->have_posts() ):
          while( $novels->have_posts() ): $novels->the_post();
       ?>
       <!-- Post -->
       <div class="col-12 post1">
           <?php get_template_part('template_parts/content', 'archive-novel'); ?>
       </div>
       <!-- End Post -->
       <?php
            endwhile;
            wp_reset_postdata();
            endif;
       ?>
    
asked by anonymous 13.05.2018 / 01:52

1 answer

1

For this, you can use the post_parent parameter. When a post has "0" as parent, it means that it has no parent, so it is not child post.

 $args = array(
   'post_type' => 'novellist',
   'post_parent' => 0    
 );

( source )

    
13.05.2018 / 02:19