Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#19515 closed enhancement (worksforme)

Helper functions for accessing 'tax_query', 'query', 'meta_query' WP Query properties

Reported by: ejdanderson's profile ejdanderson Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.1
Component: Query Keywords: needs-patch
Focuses: Cc:

Description

In the current state, to access the 'tax_query', 'query', 'meta_query', we must do so via the global $wp_query. It would be useful have access to these properties via getters, similar to get_queried_object or get_query_var.

Example use case: Having a second loop on a page displaying a filtered or adjusted version of the main loop.

Change History (4)

#1 @ejdanderson
13 years ago

  • Severity changed from normal to minor

#2 follow-up: @scribu
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
  • Type changed from feature request to enhancement

The tax_query property is accessible from any WP_Query instance:

$my_query = new WP_Query( array(
  'tax_query' => array(
    ...
  )
) );

var_dump( $my_query->tax_query );

#3 in reply to: ↑ 2 @ejdanderson
13 years ago

Replying to scribu:

The tax_query property is accessible from any WP_Query instance:

$my_query = new WP_Query( array(
  'tax_query' => array(
    ...
  )
) );

var_dump( $my_query->tax_query );

Yes, but we could also do that with the get_queried_object. get_query_var, have_comments etc.. methods, which are just wrappers for the global $wp_query object methods. Is it because these are properties and not methods?

#4 @scribu
13 years ago

Unlike get_queried_object() and the rest, the tax_query and meta_query properties are not something you should be using very often. It's an implementation detail.

Therefore, we shouldn't promote them by adding helpers for accessing them.

Note: See TracTickets for help on using tickets.