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 4 years ago.
Just use 'post_parent'
post_parent__in.php (963 bytes) - added by nacin 4 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 @nacin5 years ago

  • Keywords has-patch added

@nacin5 years ago

@scribu4 years ago

Just use 'post_parent'

comment:2 @scribu4 years ago

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

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

comment:3 @scribu4 years ago

Similar: #16854

comment:4 @johnjamesjacoby4 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 4 years ago by johnjamesjacoby (previous) (diff)

comment:5 @nacin4 years ago

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

comment:7 @scribu4 years ago

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

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

@nacin4 years ago

comment:8 @nacin4 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;

comment:9 @nacin3 years ago

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

Duplicate of #11056.

comment:10 @nacin3 years ago

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