Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 19th, 2011  |  syntax: PHP  |  size: 0.56 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.     ?>
clone this paste RAW Paste Data