Request_Fallback
Helper class that handles integration of third party plugins and themes that cannot support the ajax filtering.
Table of Contents
- $filters : Collection
- Collection of retrieved filters instances.
- $orderby : string
- Holds the orderby parameter.
- $parameters : Collection
- Sanitize collection of parsed and requested parameters.
- $query : object
- WP Query instance.
- $post_ids : array<string|int, mixed>
- List of post ids retrieved.
- __construct() : mixed
- Initialize the fallback request handler.
- get_active_filters() : array<string|int, mixed>
- Prepare the collection of parameters that will then be used to display the active filters list.
- get_found_post_ids() : array<string|int, mixed>
- Get the list of found post ids.
- load_filters() : self
- Gr
- maybe_order_results() : void
- If an orderby parameter was found within the request, update the query instance by injecting the appropriate sorting functions/parameters.
- parse_request() : Collection
- Parses string as if it were the query string passed via a URL and sets variables in the current scope.
- prepare_requested_filters_collection() : Collection
- Apply specific modifications to the collection keys and/or values.
- set_orderby() : self
- Programmatically set the orderby parameter for the fallback handler.
- set_parameters() : self
- Programmatically set the parameters for the fallback request.
- set_wp_query() : self
- Set the query that we're working with.
- update_query_vars() : void
- Update the query instance and inject the found posts.
- 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.
Properties
$filters
Collection of retrieved filters instances.
public
Collection
$filters
$orderby
Holds the orderby parameter.
public
string
$orderby
= null
$parameters
Sanitize collection of parsed and requested parameters.
public
Collection
$parameters
$query
WP Query instance.
public
object
$query
$post_ids
List of post ids retrieved.
protected
array<string|int, mixed>
$post_ids
= []
Methods
__construct()
Initialize the fallback request handler.
public
__construct([string $parameters = null ][, string $orderby = null ]) : mixed
Parameters
- $parameters : string = null
- $orderby : string = null
Return values
mixed —get_active_filters()
Prepare the collection of parameters that will then be used to display the active filters list.
public
get_active_filters() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_found_post_ids()
Get the list of found post ids.
public
get_found_post_ids() : array<string|int, mixed>
Return values
array<string|int, mixed> —load_filters()
Gr
public
load_filters() : self
Return values
self —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 —parse_request()
Parses string as if it were the query string passed via a URL and sets variables in the current scope.
public
parse_request(string $string) : Collection
Parameters
- $string : string
Return values
Collection —prepare_requested_filters_collection()
Apply specific modifications to the collection keys and/or values.
public
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 —set_orderby()
Programmatically set the orderby parameter for the fallback handler.
public
set_orderby(string $orderby) : self
Parameters
- $orderby : string
Return values
self —set_parameters()
Programmatically set the parameters for the fallback request.
public
set_parameters(Collection $parameters) : self
Parameters
- $parameters : Collection
Return values
self —set_wp_query()
Set the query that we're working with.
public
set_wp_query(WP_Query $query) : self
Parameters
- $query : WP_Query
Return values
self —update_query_vars()
Update the query instance and inject the found posts.
public
update_query_vars(WP_Query &$query[, array<string|int, mixed> $args = [] ]) : void
Parameters
- $query : WP_Query
- $args : array<string|int, mixed> = []
-
additional args that can be merged within the get_filtered_post_ids query args.
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(WP_Query $the_query[, array<string|int, mixed> $additional_args = [] ]) : array<string|int, mixed>
Parameters
- $the_query : WP_Query
- $additional_args : array<string|int, mixed> = []
-
additional args that can be merged within the get_filtered_post_ids query args.