WC_Query
in package
WC_Query Class.
Table of Contents
- $query_vars : array
- Query vars to add to wp.
- $chosen_attributes : array
- Stores chosen attributes.
- $product_query : WP_Query
- Reference to the main product query on the page.
- __construct() : mixed
- Constructor for the query class. Hooks in methods.
- add_endpoints() : mixed
- Add endpoints for query vars.
- add_query_vars() : array
- Add query vars.
- adjust_posts_count() : int
- This function used to be hooked to found_posts and adjust the posts count when the filtering by attribute widget was used and variable products were present. Now it isn't hooked anymore and does nothing but return the input unchanged, since the pull request in which it was introduced has been reverted.
- get_catalog_ordering_args() : 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() : string
- Get page title for an endpoint.
- get_endpoints_mask() : int
- Endpoint mask describing the places the endpoint should be added.
- get_errors() : mixed
- Get any errors from querystring.
- get_layered_nav_chosen_attributes() : array
- Get an array of attributes and terms selected with the layered nav widget.
- get_main_meta_query() : array
- Get the meta query which was used by the main query.
- get_main_query() : WP_Query
- Get the main query which product queries ran against.
- get_main_search_query_sql() : mixed
- 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
- Appends meta queries to an array.
- get_products_in_view() : mixed
- Get an unpaginated list all product IDs (both filtered and unfiltered). Makes use of transients.
- get_query_vars() : array
- Get query vars.
- get_tax_query() : array
- Appends tax queries to an array.
- handle_get_posts() : array
- Handler for the 'the_posts' WP filter.
- init_query_vars() : mixed
- Init query vars by loading options.
- layered_nav_init() : mixed
- Layered nav init.
- layered_nav_query() : mixed
- Layered Nav post filter.
- order_by_popularity_post_clauses() : array
- WP Core does not let us change the sort direction for individual orderby params - https://core.trac.wordpress.org/ticket/17065.
- order_by_price_asc_post_clauses() : array
- Handle numeric price sorting.
- order_by_price_desc_post_clauses() : array
- Handle numeric price sorting.
- order_by_rating_post_clauses() : array
- Order by rating post clauses.
- parse_request() : mixed
- Parse the request and look for query vars - endpoints may not be supported.
- pre_get_posts() : mixed
- Hook into pre_get_posts to do the main product query.
- price_filter_post_clauses() : array
- Custom query used to filter products by price.
- product_query() : mixed
- Query the products, applying sorting/ordering etc.
- rating_filter_meta_query() : array
- Return a meta query for filtering by rating.
- remove_add_to_cart_pagination() : string
- Remove the add-to-cart param from pagination urls.
- remove_ordering_args() : mixed
- Remove ordering queries.
- remove_posts_where() : mixed
- Remove the posts_where filter.
- remove_product_query() : mixed
- Remove the query.
- remove_product_query_filters() : array
- Pre_get_posts above may adjust the main query to add WooCommerce logic. When this query is done, we need to ensure all custom filters are removed.
- search_post_excerpt() : mixed
- Search post excerpt.
- stock_status_meta_query() : array
- Returns a meta query to handle product stock status.
- visibility_meta_query() : array
- Returns a meta query to handle product visibility.
- wpseo_metadesc() : string
- WP SEO meta description.
- wpseo_metakey() : string
- WP SEO meta key.
- get_current_posts() : array
- Get the posts (or the ids of the posts) found in the current WP loop.
- get_layered_nav_chosen_attributes_inst() : array
- Instance version of get_layered_nav_chosen_attributes, needed for unit tests.
- append_product_sorting_table_join() : string
- Join wc_product_meta_lookup to posts if not already joined.
- is_showing_page_on_front() : bool
- Are we currently on the front page?
- page_on_front_is() : bool
- Is the front page a page we define?
Properties
$query_vars
Query vars to add to wp.
public
array
$query_vars
= array()
$chosen_attributes
Stores chosen attributes.
private
static array
$chosen_attributes
$product_query
Reference to the main product query on the page.
private
static WP_Query
$product_query
Methods
__construct()
Constructor for the query class. Hooks in methods.
public
__construct() : mixed
Return values
mixedadd_endpoints()
Add endpoints for query vars.
public
add_endpoints() : mixed
Return values
mixedadd_query_vars()
Add query vars.
public
add_query_vars(array $vars) : array
Parameters
- $vars : array
-
Query vars.
Return values
arrayadjust_posts_count()
This function used to be hooked to found_posts and adjust the posts count when the filtering by attribute widget was used and variable products were present. Now it isn't hooked anymore and does nothing but return the input unchanged, since the pull request in which it was introduced has been reverted.
public
adjust_posts_count(int $count, WP_Query $query) : int
Parameters
- $count : int
-
Original posts count, as supplied by the found_posts filter.
- $query : WP_Query
-
The current WP_Query object.
Tags
Return values
int — Adjusted posts count.get_catalog_ordering_args()
Returns an array of arguments for ordering products based on the selected values.
public
get_catalog_ordering_args([string $orderby = '' ][, string $order = '' ]) : array
Parameters
- $orderby : string = ''
-
Order by param.
- $order : string = ''
-
Order param.
Return values
arrayget_current_endpoint()
Get query current active query var.
public
get_current_endpoint() : string
Return values
stringget_endpoint_title()
Get page title for an endpoint.
public
get_endpoint_title(string $endpoint[, string $action = '' ]) : string
Parameters
- $endpoint : string
-
Endpoint key.
- $action : string = ''
-
Optional action or variation within the endpoint.
Tags
Return values
string — The page title.get_endpoints_mask()
Endpoint mask describing the places the endpoint should be added.
public
get_endpoints_mask() : int
Tags
Return values
intget_errors()
Get any errors from querystring.
public
get_errors() : mixed
Return values
mixedget_layered_nav_chosen_attributes()
Get an array of attributes and terms selected with the layered nav widget.
public
static get_layered_nav_chosen_attributes() : array
Return values
arrayget_main_meta_query()
Get the meta query which was used by the main query.
public
static get_main_meta_query() : array
Return values
arrayget_main_query()
Get the main query which product queries ran against.
public
static get_main_query() : WP_Query
Return values
WP_Queryget_main_search_query_sql()
Based on WP_Query::parse_search
public
static get_main_search_query_sql() : mixed
Return values
mixedget_main_tax_query()
Get the tax query which was used by the main query.
public
static get_main_tax_query() : array
Return values
arrayget_meta_query()
Appends meta queries to an array.
public
get_meta_query([array $meta_query = array() ][, bool $main_query = false ]) : array
Parameters
- $meta_query : array = array()
-
Meta query.
- $main_query : bool = false
-
If is main query.
Return values
arrayget_products_in_view()
Get an unpaginated list all product IDs (both filtered and unfiltered). Makes use of transients.
public
get_products_in_view() : mixed
Tags
Return values
mixedget_query_vars()
Get query vars.
public
get_query_vars() : array
Return values
arrayget_tax_query()
Appends tax queries to an array.
public
get_tax_query([array $tax_query = array() ][, bool $main_query = false ]) : array
Parameters
- $tax_query : array = array()
-
Tax query.
- $main_query : bool = false
-
If is main query.
Return values
arrayhandle_get_posts()
Handler for the 'the_posts' WP filter.
public
handle_get_posts(array $posts, WP_Query $query) : array
Parameters
- $posts : array
-
Posts from WP Query.
- $query : WP_Query
-
Current query.
Return values
arrayinit_query_vars()
Init query vars by loading options.
public
init_query_vars() : mixed
Return values
mixedlayered_nav_init()
Layered nav init.
public
layered_nav_init() : mixed
Tags
Return values
mixedlayered_nav_query()
Layered Nav post filter.
public
layered_nav_query(mixed $deprecated) : mixed
Parameters
- $deprecated : mixed
-
Deprecated.
Tags
Return values
mixedorder_by_popularity_post_clauses()
WP Core does not let us change the sort direction for individual orderby params - https://core.trac.wordpress.org/ticket/17065.
public
order_by_popularity_post_clauses(array $args) : array
This lets us sort by meta value desc, and have a second orderby param.
Parameters
- $args : array
-
Query args.
Return values
arrayorder_by_price_asc_post_clauses()
Handle numeric price sorting.
public
order_by_price_asc_post_clauses(array $args) : array
Parameters
- $args : array
-
Query args.
Return values
arrayorder_by_price_desc_post_clauses()
Handle numeric price sorting.
public
order_by_price_desc_post_clauses(array $args) : array
Parameters
- $args : array
-
Query args.
Return values
arrayorder_by_rating_post_clauses()
Order by rating post clauses.
public
order_by_rating_post_clauses(array $args) : array
Parameters
- $args : array
-
Query args.
Return values
arrayparse_request()
Parse the request and look for query vars - endpoints may not be supported.
public
parse_request() : mixed
Return values
mixedpre_get_posts()
Hook into pre_get_posts to do the main product query.
public
pre_get_posts(WP_Query $q) : mixed
Parameters
- $q : WP_Query
-
Query instance.
Return values
mixedprice_filter_post_clauses()
Custom query used to filter products by price.
public
price_filter_post_clauses(array $args, WP_Query $wp_query) : array
Parameters
- $args : array
-
Query args.
- $wp_query : WP_Query
-
WP_Query object.
Tags
Return values
arrayproduct_query()
Query the products, applying sorting/ordering etc.
public
product_query(WP_Query $q) : mixed
This applies to the main WordPress loop.
Parameters
- $q : WP_Query
-
Query instance.
Return values
mixedrating_filter_meta_query()
Return a meta query for filtering by rating.
public
rating_filter_meta_query() : array
Tags
Return values
arrayremove_add_to_cart_pagination()
Remove the add-to-cart param from pagination urls.
public
remove_add_to_cart_pagination(string $url) : string
Parameters
- $url : string
-
URL.
Return values
stringremove_ordering_args()
Remove ordering queries.
public
remove_ordering_args() : mixed
Return values
mixedremove_posts_where()
Remove the posts_where filter.
public
remove_posts_where() : mixed
Tags
Return values
mixedremove_product_query()
Remove the query.
public
remove_product_query() : mixed
Return values
mixedremove_product_query_filters()
Pre_get_posts above may adjust the main query to add WooCommerce logic. When this query is done, we need to ensure all custom filters are removed.
public
remove_product_query_filters(array $posts) : array
This is done here during the_posts filter. The input is not changed.
Parameters
- $posts : array
-
Posts from WP Query.
Return values
arraysearch_post_excerpt()
Search post excerpt.
public
search_post_excerpt([string $where = '' ]) : mixed
Parameters
- $where : string = ''
-
Where clause.
Tags
Return values
mixedstock_status_meta_query()
Returns a meta query to handle product stock status.
public
stock_status_meta_query([string $status = 'instock' ]) : array
Parameters
- $status : string = 'instock'
-
(default: 'instock').
Tags
Return values
arrayvisibility_meta_query()
Returns a meta query to handle product visibility.
public
visibility_meta_query([string $compare = 'IN' ]) : array
Parameters
- $compare : string = 'IN'
-
(default: 'IN').
Tags
Return values
arraywpseo_metadesc()
WP SEO meta description.
public
wpseo_metadesc() : string
Hooked into wpseo_ hook already, so no need for function_exist.
Return values
stringwpseo_metakey()
WP SEO meta key.
public
wpseo_metakey() : string
Hooked into wpseo_ hook already, so no need for function_exist.
Return values
stringget_current_posts()
Get the posts (or the ids of the posts) found in the current WP loop.
protected
get_current_posts() : array
Return values
array — Array of posts or post ids.get_layered_nav_chosen_attributes_inst()
Instance version of get_layered_nav_chosen_attributes, needed for unit tests.
protected
get_layered_nav_chosen_attributes_inst() : array
Return values
arrayappend_product_sorting_table_join()
Join wc_product_meta_lookup to posts if not already joined.
private
append_product_sorting_table_join(string $sql) : string
Parameters
- $sql : string
-
SQL join.
Return values
stringis_showing_page_on_front()
Are we currently on the front page?
private
is_showing_page_on_front(WP_Query $q) : bool
Parameters
- $q : WP_Query
-
Query instance.
Return values
boolpage_on_front_is()
Is the front page a page we define?
private
page_on_front_is(int $page_id) : bool
Parameters
- $page_id : int
-
Page ID.