Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#8085 closed defect (bug) (fixed)

Patch to allow 'post_parent=0' queries to be executed properly

Reported by: stefanoverna's profile stefano.verna Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.6
Component: General Keywords:
Focuses: Cc:

Description

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 $qpost_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.

Attachments (1)

query.patch (449 bytes) - added by stefano.verna 15 years ago.
The Patch

Download all attachments as: .zip

Change History (4)

@stefano.verna
15 years ago

The Patch

#1 @stefano.verna
15 years ago

sorry.. just realized that the correct function to use is is_numeric()

#2 @markjaquith
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [9774]) Allow post_parent=0 queries to work. props stefano.verna. fixes #8085

Note: See TracTickets for help on using tickets.