[wp-trac] [WordPress Trac] #8085: Patch to allow 'post_parent=0' queries to be executed properly

WordPress Trac wp-trac at lists.automattic.com
Thu Nov 6 21:08:53 GMT 2008

#8085: Patch to allow 'post_parent=0' queries to be executed properly
 Reporter:  stefano.verna  |       Owner:  anonymous
     Type:  defect         |      Status:  new      
 Priority:  normal         |   Milestone:  2.7      
Component:  General        |     Version:  2.6      
 Severity:  normal         |    Keywords:           
 I found that the following piece code doesn't work as it should:

 <?php get_posts('post_type=page&post_parent=0'); ?>

 In fact, it returns all the pages, instead of just the children of the
 root (that is, the pages with depth = 1). This is due to the check that is
 being made in WP_Query:

 if ( $q['post_parent'] )
 $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ",
 $q['post_parent'] );

 So, as $q['post_parent'] is 0 (aka false), the relative action gets
 skipped. Just replacing this check with the more appropriate is_integer()
 solves the problem.

 Patch attached.

Ticket URL: <http://trac.wordpress.org/ticket/8085>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list