Make WordPress Core

Opened 14 years ago

Closed 11 years ago

Last modified 11 years ago

#13927 closed enhancement (duplicate)

post_parent query var should accept an array

Reported by: nacin's profile nacin Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch
Focuses: Cc:


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

It'd be nice to be able to either pass an array, or introduce post_parent__in and __not_in vars.

Attachments (3)

13927.diff (1.4 KB) - added by nacin 14 years ago.
16850.diff (773 bytes) - added by scribu 13 years ago.
Just use 'post_parent'
post_parent__in.php (963 bytes) - added by nacin 13 years ago.

Download all attachments as: .zip

Change History (13)

#1 @nacin
14 years ago

  • Keywords has-patch added

14 years ago

13 years ago

Just use 'post_parent'

#2 @scribu
13 years ago

Hm... didn't think about 'post_parent__not_in'.

Last edited 13 years ago by scribu (previous) (diff)

#3 @scribu
13 years ago

Similar: #16854

#4 @johnjamesjacoby
13 years ago

Running into this as an issue with the bbPress plugin and the topics and replies widgets. Since forums can be 'private' I specifically need...

post_parent__not_in exclude private forum IDs from the widgets completely. The alternative is quite ugly, involving using meta queries and storing an additional meta entry for every topic/reply with the forum status. Ugly because if the forum status changes, every topic/reply in that forum needs to be updated.

Any way to scoot this into 3.2-early?

Last edited 13 years ago by johnjamesjacoby (previous) (diff)

#5 @nacin
13 years ago

Have a ticket number over on bbPress Trac? I'll contribute some code I wrote that will implement this via a plugin.

#7 @scribu
13 years ago

Yeah, keep in mind that you can easily implement custom query vars using filters: 'posts_where', 'posts_clauses' etc.

Last edited 13 years ago by scribu (previous) (diff)

#8 @nacin
13 years ago

Attached file will implement post_parent__in and not__in. It'll noop automatically once it's implemented in core, if added to WP::$private_query_vars. Originally this had some other code:

The other code I wrote avoided private_query_vars for the check and did this:

	$qv_test = $wp_query->fill_query_vars( array() );
	if ( isset( $qv_test['post_parent__in'] ) )
		return $where;

#9 @nacin
11 years ago

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

Duplicate of #11056.

#10 @nacin
11 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.