API / Minn\Query / PostOrder

PostOrder final class

Minn\Query\PostOrder · public/minn/src/Minn/Query/PostOrder.php · 122 lines

WP_Query's ORDER BY as the reference writes it (probe wp-query-sql): the keys it takes, what each key becomes (a column, a meta value, a FIELD() list, a seeded RAND()), and how a list or a map of keys joins with its directions. A key it does not know is dropped; none left means post_date.

Constants and properties

privateFIELDS = array ( 0 => 'name', 1 => 'author', 2 => 'date', 3 => 'title', 4 => 'modified', 5 => 'parent', 6 => 'type', )

The post fields an orderby may name, bare or with their column's post_ prefix.

privateOTHERS = array ( 0 => 'ID', 1 => 'menu_order', 2 => 'comment_count', 3 => 'rand', 4 => 'post__in', 5 => 'post_parent__in', 6 => 'post_name__in', )

The other names an orderby may use.

privateCOLUMNS = array ( 0 => 'post_name', 1 => 'post_author', 2 => 'post_date', 3 => 'post_title', 4 => 'post_modified', 5 => 'post_parent', 6 => 'post_type', 7 => 'ID', 8 => 'menu_order', 9 => 'comment_count', )
privateIN_GIVEN_ORDER = array ( 0 => 'post__in', 1 => 'post_name__in', 2 => 'post_parent__in', )

Public

staticdirection(mixed $order): string#

ASC when asked for, DESC for anything else.

staticbuild(array $q, string $table, array $metaClauses): string#

The ORDER BY body for the query's orderby and order, settling both in $q as the reference leaves them (a random or a given-order sort has no direction; a string orderby is url-decoded and slashed).

$qarray<string, mixed>
$metaClausesarray<array-key, array<string, mixed>>the meta query's clauses, by name
staticclause(string $orderby, string $table, array $metaClauses, array $q): string|false#

One orderby key as SQL, or false when the reference does not take it: a column, RAND() (seeded when asked), the primary meta clause's value (cast when it has a type), a named meta clause's cast value, or the FIELD() list that keeps post__in, post_name__in or post_parent__in in the order given.

$metaClausesarray<array-key, array<string, mixed>>
$qarray<string, mixed>

Internals 2

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

privatemap(array $orderby, string $table, array $metaClauses, array $q): string#
$orderbyarray<array-key, mixed>key => direction @param array<string, mixed> $q
privatefield(string $orderby, string $table, array $q): string#

A FIELD() list in the order the variable gives, or '' when it gives none. @param array<string, mixed> $q

$qarray<string, mixed>