Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#36344 closed enhancement (wontfix)

WP_Query: Allow passing a string for post_parent__not_in

Reported by: tavo962's profile tavo962 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4.2
Component: Query Keywords:
Focuses: Cc:

Description

Improvement for: post-parent-not-in in line 2772. could not use post--not-in as a parameter in a string.

File: wp-includes/query.php
Line: 2772
Type: Enhancement

Example:
if the following query is run it does not work without the improvement

query_posts( 'post__not_in=2&post_status=publish&posts_per_page=15&paged=1' );

URL GitHub: https://github.com/WordPress/WordPress/pull/192

Remove:

$post_parent__not_in = implode( ',',  array_map( 'absint', $q['post_parent__not_in'] ) );

Add:

$post_parent__not_in = implode( ',',  array_map( 'absint', is_string( $q['post_parent__not_in'] ) ? explode( ',', $q['post_parent__not_in'] ) : $q['post_parent__not_in'] ) );

Greetings from Mexico.

Best regards
Gustavo Martínez

Attachments (2)

Screen Shot 2016-03-26 at 01.55.41.png (196.9 KB) - added by tavo962 9 years ago.
GitHub
Screen Shot 2016-03-26 at 01.55.34.png (112.8 KB) - added by tavo962 9 years ago.
GitHub

Download all attachments as: .zip

Change History (5)

#1 @swissspidy
9 years ago

  • Summary changed from Improvement for: post_parent__not_in in line 2772. could not use post__not_in as a parameter in a string. to WP_Query: Allow passing a string for post_parent__not_in

#2 @swissspidy
9 years ago

post_parent__not_in is not the only parameter that is required to be an array. In fact, only few can be either a string or an array, e.g post_type, orderby and post_status. For these params it makes sense, because most of the time you'll only need to pass a single string.

In my opinion array-only makes sense for post_parent__not_in because developers usually populate it with dynamic values (e.g. from an other query).

In any case, if this enhancement gets traction, post_parent__not_in shouldn't be the only one being changed.

#3 @DrewAPicture
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I agree with @swissspidy's reasoning about why some arguments should be expected to accept arrays only vs arrays or strings. Closing as wontfix.

Note: See TracTickets for help on using tickets.