SHARE
TWEET

Untitled

a guest Dec 19th, 2011 30 Never
  1.  <?php
  2.     //pre_get_posts filter is called before WordPress gets posts
  3.     add_filter( 'pre_get_posts', 'my_get_posts' );
  4.  
  5.     function my_get_posts( $query ) {
  6.         //if page is an archive and post_parent is not set and post_type is the post type in question
  7.         if ( is_archive() && false == $query->query_vars['post_parent'] &&  $query->query_vars['post_type'] == 'my_post_type')
  8.             //set post_parent to 0, which is the default post_parent for top level posts
  9.             $query->set( 'post_parent', 0 );
  10.         return $query;
  11.     }
  12.     ?>
RAW Paste Data
Top