PHP Class WC_Query

Show file Open project: woocommerce/woocommerce Class Usage Examples

Public Properties

Property Type Description
$query_vars

Public Methods

Method Description
__construct ( ) Constructor for the query class. Hooks in methods.
add_endpoints ( ) Add endpoints for query vars.
add_query_vars ( array $vars ) : array Add query vars.
get_catalog_ordering_args ( $orderby = '', $order = '' ) : array Returns an array of arguments for ordering products based on the selected values.
get_current_endpoint ( ) : string Get query current active query var.
get_endpoint_title ( $endpoint ) : string Get page title for an endpoint.
get_errors ( ) Get any errors from querystring.
get_layered_nav_chosen_attributes ( ) Layered Nav Init.
get_main_meta_query ( ) : array Get the meta query which was used by the main query.
get_main_search_query_sql ( ) Based on WP_Query::parse_search
get_main_tax_query ( ) : array Get the tax query which was used by the main query.
get_meta_query ( array $meta_query = [] ) : array Appends meta queries to an array.
get_products_in_view ( ) Get an unpaginated list all product ID's (both filtered and unfiltered). Makes use of transients.
get_query_vars ( ) : array Get query vars.
get_tax_query ( array $tax_query = [] ) : array Appends tax queries to an array.
init_query_vars ( ) Init query vars by loading options.
layered_nav_init ( )
layered_nav_query ( $filtered_posts ) Layered Nav post filter.
order_by_popularity_post_clauses ( array $args ) : array WP Core doens't let us change the sort direction for invidual orderby params - https://core.trac.wordpress.org/ticket/17065.
order_by_rating_post_clauses ( array $args ) : array Order by rating post clauses.
parse_request ( ) Parse the request and look for query vars - endpoints may not be supported.
pre_get_posts ( mixed $q ) Hook into pre_get_posts to do the main product query.
product_query ( mixed $q ) Query the products, applying sorting/ordering etc. This applies to the main wordpress loop.
rating_filter_meta_query ( ) : array Return a meta query for filtering by rating.
remove_ordering_args ( ) Remove ordering queries.
remove_posts_where ( ) Remove the posts_where filter.
remove_product_query ( ) Remove the query.
search_post_excerpt ( string $where = '' ) : string Search post excerpt.
stock_status_meta_query ( string $status = 'instock' ) : array Returns a meta query to handle product stock status.
visibility_meta_query ( string $compare = 'IN' ) : array Returns a meta query to handle product visibility.
wpseo_metadesc ( ) : string WP SEO meta description.
wpseo_metakey ( ) : string WP SEO meta key.

Protected Methods

Method Description
get_endpoints_mask ( ) : integer Endpoint mask describing the places the endpoint should be added.

Private Methods

Method Description
is_showing_page_on_front ( $q ) : boolean Are we currently on the front page?
page_on_front_is ( $page_id ) : boolean Is the front page a page we define?
price_filter_meta_query ( ) : array Return a meta query for filtering by price.

Method Details

__construct() public method

Constructor for the query class. Hooks in methods.
public __construct ( )

add_endpoints() public method

Add endpoints for query vars.
public add_endpoints ( )

add_query_vars() public method

Add query vars.
public add_query_vars ( array $vars ) : array
$vars array
return array

get_catalog_ordering_args() public method

Returns an array of arguments for ordering products based on the selected values.
public get_catalog_ordering_args ( $orderby = '', $order = '' ) : array
return array

get_current_endpoint() public method

Get query current active query var.
public get_current_endpoint ( ) : string
return string

get_endpoint_title() public method

Get page title for an endpoint.
public get_endpoint_title ( $endpoint ) : string
return string

get_endpoints_mask() protected method

Endpoint mask describing the places the endpoint should be added.
Since: 2.6.2
protected get_endpoints_mask ( ) : integer
return integer

get_errors() public method

Get any errors from querystring.
public get_errors ( )

get_layered_nav_chosen_attributes() public static method

Layered Nav Init.

get_main_meta_query() public static method

Get the meta query which was used by the main query.
public static get_main_meta_query ( ) : array
return array

get_main_search_query_sql() public static method

Based on WP_Query::parse_search
public static get_main_search_query_sql ( )

get_main_tax_query() public static method

Get the tax query which was used by the main query.
public static get_main_tax_query ( ) : array
return array

get_meta_query() public method

Appends meta queries to an array.
public get_meta_query ( array $meta_query = [] ) : array
$meta_query array
return array

get_products_in_view() public method

Get an unpaginated list all product ID's (both filtered and unfiltered). Makes use of transients.
Deprecation: 2.6.0 due to performance concerns

get_query_vars() public method

Get query vars.
public get_query_vars ( ) : array
return array

get_tax_query() public method

Appends tax queries to an array.
public get_tax_query ( array $tax_query = [] ) : array
$tax_query array
return array

init_query_vars() public method

Init query vars by loading options.
public init_query_vars ( )

layered_nav_init() public method

Deprecation: 2.6.0
public layered_nav_init ( )

layered_nav_query() public method

Layered Nav post filter.
Deprecation: 2.6.0 due to performance concerns
public layered_nav_query ( $filtered_posts )

order_by_popularity_post_clauses() public method

This lets us sort by meta value desc, and have a second orderby param.
public order_by_popularity_post_clauses ( array $args ) : array
$args array
return array

order_by_rating_post_clauses() public method

Order by rating post clauses.
Deprecation: 2.7.0
public order_by_rating_post_clauses ( array $args ) : array
$args array
return array

parse_request() public method

Parse the request and look for query vars - endpoints may not be supported.
public parse_request ( )

pre_get_posts() public method

Hook into pre_get_posts to do the main product query.
public pre_get_posts ( mixed $q )
$q mixed query object

product_query() public method

Query the products, applying sorting/ordering etc. This applies to the main wordpress loop.
public product_query ( mixed $q )
$q mixed

rating_filter_meta_query() public method

Return a meta query for filtering by rating.
public rating_filter_meta_query ( ) : array
return array

remove_ordering_args() public method

Remove ordering queries.

remove_posts_where() public method

Remove the posts_where filter.
public remove_posts_where ( )

remove_product_query() public method

Remove the query.

search_post_excerpt() public method

Search post excerpt.
public search_post_excerpt ( string $where = '' ) : string
$where string (default: '')
return string (modified where clause)

stock_status_meta_query() public method

Returns a meta query to handle product stock status.
public stock_status_meta_query ( string $status = 'instock' ) : array
$status string (default: 'instock')
return array

visibility_meta_query() public method

Returns a meta query to handle product visibility.
public visibility_meta_query ( string $compare = 'IN' ) : array
$compare string (default: 'IN')
return array

wpseo_metadesc() public method

Hooked into wpseo_ hook already, so no need for function_exist.
public wpseo_metadesc ( ) : string
return string

wpseo_metakey() public method

Hooked into wpseo_ hook already, so no need for function_exist.
public wpseo_metakey ( ) : string
return string

Property Details

$query_vars public property

public $query_vars