Make WordPress Core

Opened 15 years ago

Closed 12 years ago

Last modified 12 years ago

#11056 closed enhancement (fixed)

More Flexibility in args['post_parent']

Reported by: miqrogroove's profile miqrogroove Owned by: markjaquith's profile markjaquith
Milestone: 3.6 Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch commit 3.6-early needs-docs
Focuses: Cc:

Description

I am struggling to reduce query count on some of my custom code, and frankly I can't see a way to do it in the existing code base.

One of the stumbling blocks is get_children() relying on the WP_Query::get_posts() restriction for is_numeric($qpost_parent?)

The cost is 3 queries for every call to get_children().

Either I am incredibly dense about how attachment queries are supposed to work, or there needs to be a way to query multiple parents in one call.

Attachments (4)

post-parent-in.diff (2.9 KB) - added by wonderboymusic 12 years ago.
post-parent-in-tests.diff (2.2 KB) - added by wonderboymusic 12 years ago.
11056.diff (3.0 KB) - added by kovshenin 12 years ago.
11056.tests.diff (3.2 KB) - added by kovshenin 12 years ago.

Download all attachments as: .zip

Change History (24)

#1 @miqrogroove
15 years ago

p.s. I might play around with the posts_where_paged filter and see what that gets me.

#2 @miqrogroove
15 years ago

  • Milestone changed from 3.0 to Future Release

The filter I wrote still works so far. It's ugly but I don't have the time to hack WP_Query before beta starts.

#3 @wonderboymusic
12 years ago

  • Keywords has-patch added
  • Milestone changed from Future Release to 3.5

Introduce post_parent__in, post_parent__not_in - patch attached.

Example usage:

php -r "require 'wp-load.php'; \
print_r( get_posts( array( 'post_parent__in' => array( 47 ), 'post_type' => 'page', 'orderby' => 'post_parent__in' ) ) );"

#4 @nacin
12 years ago

See #13927, attachment:13927.diff:ticket:13927. This one looks a bit more complete, and is certainly updated for trunk, at least.

#5 @nacin
12 years ago

#13927 was marked as a duplicate.

#6 @wonderboymusic
12 years ago

yeah, I grep'd for post__in and went from there - your spirit lives on in the middle there

#7 @nacin
12 years ago

  • Owner changed from ryan to markjaquith
  • Status changed from new to assigned

Looks good to me. Mark?

#8 @nacin
12 years ago

  • Keywords commit added

#9 @DJPaul
12 years ago

  • Cc djpaul@… added

#10 @ryan
12 years ago

  • Keywords needs-unit-tests added

#11 @nacin
12 years ago

  • Priority changed from high to normal

Agreed with Ryan, could use some tests.

#12 @wonderboymusic
12 years ago

attached some Unit Tests

#13 @nacin
12 years ago

post-parent-in-tests.diff look good at a glance, but these tests also pass without the post_parent__in patch applied.

#14 @nacin
12 years ago

  • Keywords 3.6-early added
  • Milestone changed from 3.5 to Future Release

#15 @Japh
12 years ago

  • Cc japh@… added

This solves #9470.

#16 @wonderboymusic
12 years ago

  • Milestone changed from Future Release to 3.6

@kovshenin
12 years ago

#17 @kovshenin
12 years ago

  • Cc kovshenin added
  • Keywords needs-unit-tests removed

Refreshed in 11056.diff and added tests in 11056.tests.diff run with --group 11056.

#18 @nacin
12 years ago

In 1217/tests:

Tests for post_parent__in and post_parent__not_in. props kovshenin. see #11056.

#19 @nacin
12 years ago

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

In 23436:

WP_Query: post_parent__in and post_parent__not_in. props wonderboymusic. fixes #11056.

#20 @alexvorn2
12 years ago

  • Keywords needs-docs added
Note: See TracTickets for help on using tickets.