Make WordPress Core

Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#13927 closed enhancement (duplicate)

post_parent query var should accept an array

Reported by: 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 5 years ago.
16850.diff (773 bytes) - added by scribu 5 years ago.
Just use 'post_parent'
post_parent__in.php (963 bytes) - added by nacin 5 years ago.

Download all attachments as: .zip

Change History (13)

#1 @nacin
5 years ago

  • Keywords has-patch added

5 years ago

5 years ago

Just use 'post_parent'

#2 @scribu
5 years ago

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

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

#3 @scribu
5 years ago

Similar: #16854

#4 @johnjamesjacoby
5 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...


...to 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 5 years ago by johnjamesjacoby (previous) (diff)

#5 @nacin
5 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
5 years ago

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

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

5 years ago

#8 @nacin
5 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
3 years ago

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

Duplicate of #11056.

#10 @nacin
3 years ago

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