WordPress.org

Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#14600 closed enhancement (fixed)

Make $wp_query->query always be an array

Reported by: scribu Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version:
Component: Query Keywords: has-patch commit
Focuses: Cc:

Description (last modified by scribu)

Currently, if you do this:

$query = new WP_Query( array( 'tag' => 'foobar', 'year' => 2010 ) );

$query->query will be array( 'tag' => 'foobar', 'year' => 2010 ).

If you do

$query = new WP_Query('tag=foobar&year=2010');

$query->query will be tag=foobar&year=2010.

I think it would be more useful if $query->query will be an array in both cases. Currently, if you want to check that variable from a filter, you always have to call wp_parse_args() yourself:

function my_posts_where($sql, $wp_query) {
    $wp_query->query = wp_parse_args($wp_query->query);
    if ( isset($wp_query->query['some-var'] )
        // do something

    ...
}
add_filter('posts_where', 'my_posts_where');

Attachments (1)

14600.diff (582 bytes) - added by scribu 9 years ago.

Download all attachments as: .zip

Change History (6)

#1 @scribu
9 years ago

  • Description modified (diff)

@scribu
9 years ago

#2 @Denis-de-Bernardy
9 years ago

  • Cc Denis-de-Bernardy added

#3 @scribu
9 years ago

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

(In [15501]) Safer hierarchical display check. Fixes #14600; See #14579

#4 @hakre
9 years ago

More simple & saves lines of code. Thx for fixing.

#5 @scribu
9 years ago

(In [15547]) update WP_Query docs. See #14600

Note: See TracTickets for help on using tickets.