Query
Overview
The Query module builds WP_Query, get_posts(), and reusable nested query clauses. It is one of the main consumers of the shared Args and Clause infrastructure.
Types in this module
Lipe\Lib\Query\Get_PostsLipe\Lib\Query\Query_ArgsLipe\Lib\Query\UtilsLipe\Lib\Query\Clause\Date_QueryLipe\Lib\Query\Clause\Date_Query_Interface(interface)Lipe\Lib\Query\Clause\Date_Query_Trait(trait)Lipe\Lib\Query\Clause\Meta_QueryLipe\Lib\Query\Clause\Meta_Query_Interface(interface)Lipe\Lib\Query\Clause\Meta_Query_Trait(trait)Lipe\Lib\Query\Clause\Tax_QueryLipe\Lib\Query\Clause\Tax_Query_Interface(interface)Lipe\Lib\Query\Clause\Tax_Query_Trait(trait)
Query_Args
Primary fluent wrapper for building a WP_Query argument array.
Key public methods
public function orderby(array|string $orderby, string $order = ''): voidpublic function merge_query(\WP_Query $query): voidpublic function get_light_args(): arraypublic function __construct(array $existing)public function merge(ArgsRules $overrides): voidpublic function get_args(): array
Query_Args also implements Date_Query_Interface, Meta_Query_Interface, and Tax_Query_Interface, adding the date_query(), meta_query(), and tax_query() factories documented below.
Example
<?php
use Lipe\Lib\Query\Query_Args;
$query = new Query_Args([]);
$query->post_type = 'book';
$query->posts_per_page = 12;
$query->orderby('menu_order', 'ASC');
$posts = new WP_Query($query->get_args());
Get_Posts
Specialized get_posts() wrapper that extends Query_Args with aliases such as numberposts, category, include, and exclude.
Utils
Singleton helper that returns the lightest possible WP_Query arguments by disabling found-row counting, term/meta cache priming, and limiting to published posts.
Key public methods
public function get_light_query_args(array $args): array
Date_Query
Fluent builder for the nested date_query argument of a WP_Query. Obtained via Query_Args::date_query() rather than constructed directly.
Key public methods
public function after(string $year, ?string $month = null, ?string $day = null): staticpublic function after_string(string $date): staticpublic function before(string $year, ?string $month = null, ?string $day = null): staticpublic function before_string(string $date): staticpublic function column(string $column): staticpublic function compare(string $compare): staticpublic function inclusive(bool $inclusive = true): staticpublic function year(array|int $year): staticpublic function month(array|int $month): staticpublic function week(array|int $week): staticpublic function day(array|int $day): staticpublic function hour(array|int $hour): staticpublic function minute(array|int $minute): staticpublic function second(array|int $second): staticpublic function dayofyear(array|int $dayofyear): staticpublic function dayofweek(array|int $dayofweek): staticpublic function dayofweek_iso(array|int $dayofweek_iso): staticpublic function next_clause(): staticpublic function flatten(ArgsRules $args_class): void
Also inherits the nested-clause plumbing from Args\Clause (__construct(), set_parent_clause(), relation(), nested_clause(), parent_clause(), set_is_flattended(), is_flattended()) — see the Args module.
Example
<?php
use Lipe\Lib\Query\Query_Args;
$query = new Query_Args([]);
$query->date_query()
->after('2020', '01', '01')
->before('2020', '12', '31')
->inclusive();
$posts = new WP_Query($query->get_args());
Date_Query_Interface interface
Contract for argument objects that expose a date_query() factory.
Methods
public function date_query(): Date_Query
Date_Query_Trait trait
Adds the date_query() factory (and its backing $date_query property) to a fluent args class.
Key public methods
public function date_query(): Date_Query
Meta_Query
Fluent builder for the nested meta_query argument of a WP_Query, Get_Terms, and similar. Obtained via meta_query() rather than constructed directly.
Key public methods
public function equals($key, string $value): staticpublic function not_equals($key, string $value): staticpublic function greater_than($key, string $value): staticpublic function greater_than_or_equal($key, string $value): staticpublic function less_than($key, string $value): staticpublic function less_than_or_equal($key, string $value): staticpublic function like($key, string $value): staticpublic function not_like($key, string $value): staticpublic function in($key, array $values): staticpublic function not_in($key, array $values): staticpublic function between($key, array $values): staticpublic function not_between($key, array $values): staticpublic function exists($key): staticpublic function not_exists($key): staticpublic function advanced(string $type = '', string $compare_key = '', string $type_key = ''): staticpublic function flatten(ArgsRules $args_class): void
Also inherits the nested-clause plumbing from Args\Clause (__construct(), set_parent_clause(), relation(), nested_clause(), parent_clause(), set_is_flattended(), is_flattended()) — see the Args module.
Example
<?php
use Lipe\Lib\Query\Query_Args;
$query = new Query_Args([]);
$query->meta_query()->equals('featured', '1');
$posts = new WP_Query($query->get_args());
Meta_Query_Interface interface
Contract for argument objects that expose a meta_query() factory.
Methods
public function meta_query(): Meta_Query
Meta_Query_Trait trait
Adds the meta_query() factory, its backing $meta_query property, and the top-level $meta_key, $meta_value, $meta_compare, $meta_compare_key, $meta_type, and $meta_type_key properties to a fluent args class.
Key public methods
public function meta_query(): Meta_Query
Tax_Query
Fluent builder for the nested tax_query argument of a WP_Query. Obtained via Query_Args::tax_query() rather than constructed directly.
Key public methods
public function and(array $terms, string $taxonomy, bool $children = true, string $field = 'term_id'): staticpublic function in(array $terms, string $taxonomy, bool $children = true, string $field = 'term_id'): staticpublic function not_in(array $terms, string $taxonomy, bool $children = true, string $field = 'term_id'): staticpublic function exists(string $taxonomy): staticpublic function not_exists(string $taxonomy): staticpublic function flatten(ArgsRules $args_class): void
Also inherits the nested-clause plumbing from Args\Clause (__construct(), set_parent_clause(), relation(), nested_clause(), parent_clause(), set_is_flattended(), is_flattended()) — see the Args module.
Example
<?php
use Lipe\Lib\Query\Query_Args;
$query = new Query_Args([]);
$query->tax_query()->in(['fiction'], 'genre', false, 'slug');
$posts = new WP_Query($query->get_args());
Tax_Query_Interface interface
Contract for argument objects that expose a tax_query() factory.
Methods
public function tax_query(): Tax_Query
Tax_Query_Trait trait
Adds the tax_query() factory, its backing $tax_query property, and the classic category/tag properties ($cat, $category__and, $category__in, $category__not_in, $category_name, $tag, $tag__and, $tag__in, $tag__not_in, $tag_id, $tag_slug__and, $tag_slug__in) to a fluent args class.
Key public methods
public function tax_query(): Tax_Query