BlocksWpQuery
extends WP_Query
in package
BlocksWpQuery query.
Wrapper for WP Query with additional helper methods. Allows query args to be set and parsed without doing running it, so that a cache can be used.
Tags
Table of Contents
- __construct() : mixed
- Constructor.
- get_cached_posts() : array<string|int, WP_Post>|array<string|int, int>
- Get cached posts, if a cache exists.
Methods
__construct()
Constructor.
public
__construct([string|array<string|int, mixed> $query = '' ]) : mixed
Sets up the WordPress query, if parameter is not empty.
Unlike the constructor in WP_Query, this does not RUN the query.
Parameters
- $query : string|array<string|int, mixed> = ''
-
URL query string or array of vars.
Return values
mixed —get_cached_posts()
Get cached posts, if a cache exists.
public
get_cached_posts([string $transient_version = '' ]) : array<string|int, WP_Post>|array<string|int, int>
A hash is generated using the array of query_vars. If doing custom queries via filters such as posts_where (where the SQL query is manipulated directly) you can still ensure there is a unique hash by injecting custom query vars via the parse_query filter. For example:
add_filter( 'parse_query', function( $wp_query ) {
$wp_query->query_vars['my_custom_query_var'] = true;
} );
Doing so won't have any negative effect on the query itself, and it will cause the hash to change.
Parameters
- $transient_version : string = ''
-
Transient version to allow for invalidation.