Advertisement
Guest User

Untitled

a guest
Dec 19th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  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.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement