Request implements Registerable Uses Counters_Aware, Params_Provider, Query_Aware

Responsible of handling query filtering requests.

Interfaces, Classes and Traits

Registerable

Table of Contents

$cached_query  : WP_Query
The query object.
$reset  : bool
Whether or not the request is a reset request.
$filters  : Collection
Collection of the filter models loaded.
$is_404  : bool
Determine if the filtering request produced no results.
$orderby  : bool|string
Holds the sorting method of the query.
$paged  : bool|int
Holds the paged argument for the query.
$parameters  : Collection
Collection of requested parameters.
$post_ids  : array<string|int, mixed>
List of post ids found.
$request  : Collection
Collection of the submitted values through the search form.
generate_result_count()  : string
Use the WC template to generate the results counter.
get_counts()  : array<string|int, mixed>
Loop through the available filters and print a list of counters for each available choice indexed by the filter.
get_filters()  : Collection
Get the list of filters requested.
get_found_posts()  : int
Get the appropriate count for the found posts property.
get_orderby()  : string|bool
Determine if an orderby parameter was provided.
get_paged()  : int|bool
Get the paged parameter of the request.
get_post_ids()  : array<string|int, mixed>
Get the list of post ids found.
get_processed_filters()  : Collection
Get the list of filters loaded.
inject_template()  : void
Send the output back via json.
intercept()  : void
Intercept the search request, load the hooks and buffer the output.
maybe_insert_search_query()  : void
If a filter was found within the request, update the query instance by injecting the appropriate search query.
maybe_order_results()  : void
If an orderby parameter was found within the request, update the query instance by injecting the appropriate sorting functions/parameters.
maybe_unset_tax_queries()  : void
Unset the tax queries from the query instance.
prepare_url_params()  : array<string|int, mixed>
Prepare the collection of parameters that will then be injected into the url.
register()  : void
Hook into WP.
update_query_vars()  : void
Inject the list of found post ids into the query.
array_remove_empty()  : array<string|int, mixed>
Recursively remove empty values from a collection.
attach_search_query_to_filters()  : Collection
Attach the value of the filter from the frontend request, to the `Filter` instance `search_query` attribute.
get_filtered_post_ids()  : array<string|int, mixed>
Query the database and find all post ids belonging to the selected filters.
is_main_query()  : bool
Determine if it's a query we should be filtering or not.
is_reset()  : bool
Determine if this was a reset request.
prepare_requested_filters_collection()  : Collection
Apply specific modifications to the collection keys and/or values.
process_filters()  : void
Load the filters and attach values to them.

Properties

$cached_query

The query object.

public WP_Query $cached_query

$reset

Whether or not the request is a reset request.

public bool $reset = false

$filters

Collection of the filter models loaded.

protected Collection $filters

This list contains ONLY the filters for which the user as selected values.

$is_404

Determine if the filtering request produced no results.

protected bool $is_404 = false

$orderby

Holds the sorting method of the query.

protected bool|string $orderby = false

$paged

Holds the paged argument for the query.

protected bool|int $paged = false

$parameters

Collection of requested parameters.

protected Collection $parameters

$post_ids

List of post ids found.

protected array<string|int, mixed> $post_ids = []

$request

Collection of the submitted values through the search form.

protected Collection $request

Methods

generate_result_count()

Use the WC template to generate the results counter.

public generate_result_count([mixed $query = false ][, mixed $post_ids = [] ][, mixed $filters = null ]) : string
Parameters
$query : mixed = false
$post_ids : mixed = []
$filters : mixed = null
Return values
string

get_counts()

Loop through the available filters and print a list of counters for each available choice indexed by the filter.

public get_counts([mixed $filters = false ][, mixed $values = [] ]) : array<string|int, mixed>
Parameters
$filters : mixed = false
$values : mixed = []
Return values
array<string|int, mixed>

get_filters()

Get the list of filters requested.

public get_filters([array<string|int, mixed> $filters_list = [] ]) : Collection
Parameters
$filters_list : array<string|int, mixed> = []

optional explicit filters list.

Return values
Collection

get_found_posts()

Get the appropriate count for the found posts property.

public get_found_posts(WP_Query $wp_query) : int
Parameters
$wp_query : WP_Query
Return values
int

get_orderby()

Determine if an orderby parameter was provided.

public get_orderby() : string|bool
Return values
string|bool

get_paged()

Get the paged parameter of the request.

public get_paged() : int|bool
Return values
int|bool

get_post_ids()

Get the list of post ids found.

public get_post_ids() : array<string|int, mixed>
Return values
array<string|int, mixed>

get_processed_filters()

Get the list of filters loaded.

public get_processed_filters() : Collection
Return values
Collection

inject_template()

Send the output back via json.

public inject_template() : void
Return values
void

intercept()

Intercept the search request, load the hooks and buffer the output.

public intercept() : void
Return values
void

maybe_insert_search_query()

If a filter was found within the request, update the query instance by injecting the appropriate search query.

public maybe_insert_search_query(WP_Query &$wp_query) : void
Parameters
$wp_query : WP_Query
Return values
void

maybe_order_results()

If an orderby parameter was found within the request, update the query instance by injecting the appropriate sorting functions/parameters.

public maybe_order_results(WP_Query &$query) : void
Parameters
$query : WP_Query
Return values
void

maybe_unset_tax_queries()

Unset the tax queries from the query instance.

public maybe_unset_tax_queries(WP_Query &$query) : void
Parameters
$query : WP_Query
Return values
void

prepare_url_params()

Prepare the collection of parameters that will then be injected into the url.

public prepare_url_params() : array<string|int, mixed>
Return values
array<string|int, mixed>

register()

Hook into WP.

public register() : void
Return values
void

update_query_vars()

Inject the list of found post ids into the query.

public update_query_vars(WP_Query $query) : void
Parameters
$query : WP_Query
Return values
void

array_remove_empty()

Recursively remove empty values from a collection.

private array_remove_empty(array<string|int, mixed> $haystack) : array<string|int, mixed>
Parameters
$haystack : array<string|int, mixed>
Return values
array<string|int, mixed>

attach_search_query_to_filters()

Attach the value of the filter from the frontend request, to the `Filter` instance `search_query` attribute.

private attach_search_query_to_filters(Collection $collection) : Collection

This is then later used via the get_search_query method of the Filter.

Parameters
$collection : Collection
Return values
Collection

get_filtered_post_ids()

Query the database and find all post ids belonging to the selected filters.

private get_filtered_post_ids([mixed $custom_query = false ]) : array<string|int, mixed>
Parameters
$custom_query : mixed = false
Return values
array<string|int, mixed>

is_main_query()

Determine if it's a query we should be filtering or not.

private is_main_query(WP_Query $query) : bool
Parameters
$query : WP_Query
Return values
bool

is_reset()

Determine if this was a reset request.

private is_reset() : bool
Return values
bool

prepare_requested_filters_collection()

Apply specific modifications to the collection keys and/or values.

private prepare_requested_filters_collection(Collection $collection) : Collection
  • Modify strings such as "true" or "false" to bools.
  • Remove any false (bool) value from the collection.
Parameters
$collection : Collection
Return values
Collection

process_filters()

Load the filters and attach values to them.

private process_filters(Collection $requested_filters) : void
Parameters
$requested_filters : Collection
Return values
void

Search results