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_InterfaceLipe\Lib\Query\Clause\Date_Query_TraitLipe\Lib\Query\Clause\Meta_QueryLipe\Lib\Query\Clause\Meta_Query_InterfaceLipe\Lib\Query\Clause\Meta_Query_TraitLipe\Lib\Query\Clause\Tax_QueryLipe\Lib\Query\Clause\Tax_Query_InterfaceLipe\Lib\Query\Clause\Tax_Query_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
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.
Clause builders
Date_Query
Builds a nested date_query structure.
Key methods:
public function after(string $year, ?string $month = null, ?string $day = null): Date_Querypublic function before(string $year, ?string $month = null, ?string $day = null): Date_Querypublic function compare(string $compare): Date_Querypublic function inclusive(bool $inclusive = true): Date_Querypublic function next_clause(): Date_Querypublic function flatten(ArgsRules $args_class): void
Meta_Query
Builds meta_query clauses.
Key methods:
public function equals($key, string $value): Meta_Querypublic function like($key, string $value): Meta_Querypublic function in($key, array $values): Meta_Querypublic function exists($key): Meta_Querypublic function advanced(string $type = '', string $compare_key = '', string $type_key = ''): Meta_Querypublic function flatten(ArgsRules $args_class): void
Tax_Query
Builds tax_query clauses.
Key methods:
public function and(array $terms, string $taxonomy, bool $children = true, string $field = 'term_id'): Tax_Querypublic function in(array $terms, string $taxonomy, bool $children = true, string $field = 'term_id'): Tax_Querypublic function not_in(array $terms, string $taxonomy, bool $children = true, string $field = 'term_id'): Tax_Querypublic function exists(string $taxonomy): Tax_Querypublic function flatten(ArgsRules $args_class): void
Query traits and helpers
Date_Query_Interface,Meta_Query_Interface, andTax_Query_Interfaceexpose thedate_query(),meta_query(), andtax_query()factories.Date_Query_Trait,Meta_Query_Trait, andTax_Query_Traitadd those factories to consuming query classes.Utilsexposespublic function get_light_query_args(array $args): arrayfor aggressively minimizing a query.