API / Minn\Runtime / PostQuery

PostQuery final class

Minn\Runtime\PostQuery · public/minn/src/Minn/Runtime/PostQuery.php · 425 lines

WP_Query::get_posts as the reference runs it (probe wp-query-sql): the variables parsed and handed to pre_get_posts, the clauses written piece by piece, every filter a plugin may change them through in the reference's order (suppress_filters keeps the ones it keeps), the request split into an id query when that is cheaper, the count, a single post's status check and preview, sticky posts on the home listing, and the results filters. A lookup the engine can answer from what it has read (QueryAnswers) runs every filter and no SQL, unless a plugin changes it.

Used by 1

Constants and properties

privateSHAPING = array ( 0 => 'parse_query', 1 => 'parse_tax_query', 2 => 'posts_search', 3 => 'posts_search_orderby', 4 => 'posts_where', 5 => 'posts_join', 6 => 'posts_where_paged', 7 => 'posts_groupby', 8 => 'posts_join_paged', 9 => 'posts_orderby', 10 => 'posts_distinct', 11 => 'post_limits', 12 => 'posts_fields', 13 => 'posts_clauses', 14 => 'posts_where_request', 15 => 'posts_groupby_request', 16 => 'posts_join_request', 17 => 'posts_orderby_request', 18 => 'posts_distinct_request', 19 => 'posts_fields_request', 20 => 'post_limits_request', 21 => 'posts_clauses_request', 22 => 'posts_request', 23 => 'posts_pre_query', 24 => 'split_the_query', 25 => 'posts_request_ids', )

The hooks that shape the request: an engine answer stands only while none of them has a listener.

privateMinn\Objects\Query $query
privateobject $wpdb
privateMinn\Runtime\PostQueryParts $parts
private?Closure $answer
privatereadonly Minn\Db $db

Promoted from the constructor.

Public

new__construct(Minn\Db $db)#
methodrun(Minn\Objects\Query $query, object $wpdb, mixed $urlSearch): mixed#

Runs a query object's variables and fills it in: the posts (or ids, or id => parent), the request, the counts. Returns what get_posts returns.

$wpdbobjectthe database object plugins see, so the request runs where their filters expect it
$urlSearchmixedthe search string the URL carries, if any (a search from elsewhere is url-decoded)
methodsearch(Minn\Objects\Query $query, array $q, mixed $urlSearch): string#

A search's WHERE fragment, settling the search variables (the terms, how many the string split into, the title matches its order ranks by).

$qarray<string, mixed>
methodstopwords(): array#

The search stopwords, translated and filtered. @return list<string>

@return list<string>

Internals 14

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateprepare(): void#

Parses the variables, hands them to pre_get_posts, and reads the meta query from them.

privatedefaults(array $q): void#

The defaults get_posts settles before it writes a clause. @param array<string, mixed> $q

$qarray<string, mixed>
privatepageSize(array $q): void#

posts_per_page from the option, showposts, an archive's own size or the feed's, and nopaging. @param array<string, mixed> $q

$qarray<string, mixed>
privateclauses(array $q, mixed $urlSearch): void#

Writes the clauses, in the reference's order. @param array<string, mixed> $q

$qarray<string, mixed>
privatetaxonomies(array $q): void#

The tax query's clauses (not for a single post), a taxonomy archive's types, and the compatibility variables. @param array<string, mixed> $q

$qarray<string, mixed>
privatesearchOrder(array $q): void#

A search's relevance order, ahead of the order asked for, when no other order is asked for. @param array<string, mixed> $q

$qarray<string, mixed>
privatefiltered(array $q): void#

The clause filters, paging between the first two and the rest, and posts_selection. @param array<string, mixed> $q

$qarray<string, mixed>
privatethrough(array $hooks, string $clausesHook): void#

Each piece through its filter, then all seven through the clauses filter. @param array<string, string> $hooks

$hooksarray<string, string>
privatepaging(array $q): void#

LIMIT for a listing that pages: the offset when one is given, the page's start otherwise. @param array<string, mixed> $q

$qarray<string, mixed>
privateexecute(array $q): mixed#

Writes the request, runs it (or takes posts_pre_query's answer), and finishes the results. @param array<string, mixed> $q

$qarray<string, mixed>
privateidsOnly(array $q): array#

The ids (or id => parent) a query for them returns. @param array<string, mixed> $q

$qarray<string, mixed>
privateselect(array $q, string $old, string $foundRows): void#

Runs the request: ids first, then their posts, when the query can be split that way. @param array<string, mixed> $q

$qarray<string, mixed>
privateanswered(array $q): ?array#

The ids an engine answer gives, when the query is still the one the engine wrote; null when it is not, or it has none.

$qarray<string, mixed>
@return list<int>|null
privatefoundPosts(array $q): void#

found_posts (from FOUND_ROWS() when the query paged, else the posts' count) and max_num_pages. @param array<string, mixed> $q

$qarray<string, mixed>