Query_Cache Uses Counters_Aware, Params_Provider

Query cache handler helper class.

This class handles caching of a WP Query together with a filters collection inside global variables so that they can then later be referenced when making ajax requests through the forms.

Currently used for integration with the WPT and WRO plugins.

Table of Contents

$cache_prefix  : string
Cache prefix used for setting global variables.
$filters  : Collection
Filters collection.
$orderby  : string
Orderby parameter
$post_ids  : array<string|int, mixed>
List of found posts.
$query  : WP_Query
Query instance.
$reset  : bool
Whether or not the request is to be reset.
__construct()  : mixed
Initialize the caching class.
cache()  : self
Add all items to global variables.
generate_result_count()  : string
Use the WC template to generate the results counter.
get_cache_prefix()  : string
Get the caching prefix string.
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 filters collection.
get_orderby()  : string
Get the orderby parameter.
get_post_ids()  : array<string|int, mixed>
Get the list of found posts.
get_query()  : WP_Query
Get the query instance.
is_404()  : bool
Whether or not, no posts have been found.
prepare_url_params()  : array<string|int, mixed>
Prepare the collection of parameters that will then be injected into the url.
purge()  : self
Purge the global variables.
set_cache_prefix()  : self
Specific the prefix used for the caching.
set_post_ids()  : self
Manually set post ids by sending an array of posts objects.

Properties

$cache_prefix

Cache prefix used for setting global variables.

protected string $cache_prefix

$filters

Filters collection.

protected Collection $filters

$orderby

Orderby parameter

protected string $orderby

$post_ids

List of found posts.

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

$reset

Whether or not the request is to be reset.

protected bool $reset = false

Methods

__construct()

Initialize the caching class.

public __construct(WP_Query $query, string $orderby, Collection $filters, array<string|int, mixed> $post_ids) : mixed
Parameters
$query : WP_Query
$orderby : string
$filters : Collection
$post_ids : array<string|int, mixed>
Return values
mixed

cache()

Add all items to global variables.

public cache() : self
Return values
self

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_cache_prefix()

Get the caching prefix string.

public get_cache_prefix() : string
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 filters collection.

public get_filters() : Collection
Return values
Collection

get_orderby()

Get the orderby parameter.

public get_orderby() : string
Return values
string

get_post_ids()

Get the list of found posts.

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

get_query()

Get the query instance.

public get_query() : WP_Query
Return values
WP_Query

is_404()

Whether or not, no posts have been found.

public is_404() : bool
Return values
bool

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>

purge()

Purge the global variables.

public purge() : self
Return values
self

set_cache_prefix()

Specific the prefix used for the caching.

public set_cache_prefix(string $prefix) : self
Parameters
$prefix : string
Return values
self

set_post_ids()

Manually set post ids by sending an array of posts objects.

public set_post_ids(array<string|int, mixed> $posts) : self
Parameters
$posts : array<string|int, mixed>
Return values
self

Search results