Opened 4 years ago

Closed 3 months ago

Last modified 3 months ago

#11056 closed enhancement (fixed)

More Flexibility in args['post_parent']

Reported by: miqrogroove Owned by: markjaquith
Priority: normal Milestone: 3.6
Component: Query Version:
Severity: normal Keywords: has-patch commit 3.6-early needs-docs
Cc: djpaul@…, japh@…, kovshenin

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 8 months ago.
post-parent-in-tests.diff (2.2 KB) - added by wonderboymusic 8 months ago.
11056.diff (3.0 KB) - added by kovshenin 3 months ago.
11056.tests.diff (3.2 KB) - added by kovshenin 3 months ago.

Download all attachments as: .zip

Change History (24)

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

  • 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.

  • 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' ) ) );"

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

#13927 was marked as a duplicate.

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

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

Looks good to me. Mark?

  • Keywords commit added
  • Cc djpaul@… added
  • Keywords needs-unit-tests added
  • Priority changed from high to normal

Agreed with Ryan, could use some tests.

attached some Unit Tests

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

  • Keywords 3.6-early added
  • Milestone changed from 3.5 to Future Release
  • Cc japh@… added

This solves #9470.

  • Milestone changed from Future Release to 3.6
  • Cc kovshenin added
  • Keywords needs-unit-tests removed

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

In 1217/tests:

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

  • 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.

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