API / Minn\Content / Posts

Posts final readonly class

Minn\Content\Posts · public/minn/src/Minn/Content/Posts.php · 553 lines

Reads over the posts table. A post comes back as a PostRecord; a listing is the main query's (WP_Query); rendering and escaping happen elsewhere.

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

Public

new__construct(Minn\Db $db)#
methodfind(int $id): ?Minn\Content\PostRecord#

The post with this id, or null.

methodprime(array $ids, array $taxonomies = array ( )): void#

Reads a list's posts, their meta and their terms in the given taxonomies in one query each, as update_post_caches does, so the list's rendering reads none of them again.

$idslist<int>
$taxonomieslist<string>
methodrememberRows(array $rows): void#

Keeps rows a query already read (WP_Query's whole posts), so priming those posts reads them no second time.

$rowslist<array<string, mixed>>
methodprimeRows(array $ids): void#

Reads the rows of the posts not read yet, in one query. @param list<int> $ids

$idslist<int>
methodprimeMeta(array $ids): void#

Reads the meta of the posts whose meta is not read yet, in one query (update_post_meta_cache). @param list<int> $ids

$idslist<int>
methodprimeTerms(array $ids, array $taxonomies): void#

Reads the posts' terms in the given taxonomies, in one query, for the posts some of whose taxonomies are not read yet.

$idslist<int>
$taxonomieslist<string>
methodfindByName(string $name, array $types): ?Minn\Content\PostRecord#

The post with this slug among the given types; published only unless asked otherwise.

$typeslist<string>
methodfindByNameAnyStatus(string $name, array $types): ?Minn\Content\PostRecord#

The post with this slug among the given types in any status but trash, or null. @param list<string> $types

$typeslist<string>
methodbyOldSlug(string $slug, array $types): ?Minn\Content\PostRecord#

The post that once answered to the slug: every former slug stays in `_wp_old_slug` meta, and the reference redirects it to the current link whatever the post's status (a draft or trashed post goes to its `?p=` form).

$typeslist<string>
methodpageByPath(array $segments): ?Minn\Content\PostRecord#

Walks a page hierarchy: ["sample-page", "docs"] finds the page named docs whose parent is named sample-page at the root.

$segmentslist<string>
methodpageByPathAnyStatus(array $segments): ?Minn\Content\PostRecord#

The page at a slug path in any status but trash, or null. @param list<string> $segments

$segmentslist<string>
methodbyTypedPath(array $segments, array $types): ?Minn\Content\PostRecord#

The post at a slug path among the given types (each segment's parent the one before it), in any status but trash; at the last segment the first type wins over the others, as the reference prefers the type it was asked for over the attachment it also looks at.

$segmentslist<string>
$typeslist<string>
methodpathOf(Minn\Content\PostRecord $page): string#

The slash-joined ancestry of a page: "sample-page/docs".

methodguess(string $prefix, array $types): ?Minn\Content\PostRecord#

The published post whose name starts with the given text, among the given types, as the reference guesses a destination for a missing URL: one prefix query and no order of its own, so the database's plan for it decides which match comes first (on a small table its name index, alphabetical; on a large one its type and date index, oldest first), the same on both stacks over one database.

$typeslist<string>
methodhasPublished(string $type): bool#

Whether any post of a type is published.

methodidsOfType(string $type): array#

Every post id of a type, whatever its status, as stored (strings), in the table's order. @return list<string>

@return list<string>
methodmeta(int $postId, string $key): ?string#

One meta value of a post, or null when it has none.

methodterms(int $postId, string $taxonomy): array#

The post's terms in one taxonomy, as [term_id, slug] pairs.

@return list<array{0: int, 1: string}> term id and slug pairs, by name
methodrevisionCount(int $postId): int#

How many revisions the post has.

methodprimeRevisions(array $ids): void#

Reads many posts' revision counts and latest revisions in one query, for a list that links to each post's history (a REST list).

$idslist<int>
methodlatestRevisionId(int $postId): int#

The latest revision id, an autosave counting as one, newest by date then id (probe rest-latest-revision), or 0.

methodhasNewerAutosave(int $postId, string $modifiedGmt): bool#

Whether a live post carries an autosave newer than its saved state.

methodnewest(array $types, string $column): ?string#

The newest value of a date column (post_date, post_modified, or their GMT twins) among published posts of the types given, for get_lastpostdate and get_lastpostmodified.

$typeslist<string>
methoddaysWithPosts(int $year, int $month, string $type): array#

The days of one month a published post of a type was dated on, ascending.

@return list<int>
methodarchiveBuckets(string $granularity, string $type, string $order, int $limit, string $where = '', string $join = ''): array#

The periods holding a published post of a type, newest first by default: one row per month, year, day, or week, with the count and the earliest post date inside it. A WHERE and JOIN given (what wp_get_archives' getarchives_where and getarchives_join answered) are used as they are.

@return list<array{year: int, month: int, day: int, week: int, count: int, first: string}>
methodadjacentClauses(Minn\Content\PostRecord $post, string $direction, string $taxonomy, array $sameTerms, array $excluded, string $private, int $reader): array#

The JOIN, WHERE and ORDER BY of the post before ($direction "previous") or after a post, written as the reference writes them for get_adjacent_post (probe filter-inputs), for its filters to edit: kept to $sameTerms in $taxonomy when there are some, out of the $excluded terms, and published, or private too ($private "all"), or the reader's own private ones too ($private "own").

$sameTermslist<int>
$excludedlist<int>
@return array{0: string, 1: string, 2: string}
methodadjacentId(string $join, string $where, string $sort): int#

The post the clauses find (as their filters left them), or 0.

methodarchiveList(string $type, string $orderBy, string $order, int $limit, string $where = '', string $join = ''): array#

Published posts of a type for a post-by-post archive, by date or by title; a WHERE and JOIN given are used as they are (archiveBuckets).

@return list<PostRecord>
methodmonthBefore(int $year, int $month, string $type): ?array#

The nearest month before one with a published post of a type, as [year, month], or null.

methodmonthAfter(int $year, int $month, string $type): ?array#

The nearest month after one with a published post of a type, as [year, month], or null.

methodnewestAutosave(int $postId, int $userId = 0): ?Minn\Content\PostRecord#

The newest autosave of a post (by date, then id), by one author or, given 0, any (probe revision-more); null when there is none.

methodfirstCategorySlug(int $postId): ?string#

The slug of the post's first category, or null.

Internals 9

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

privaterecord(?array $row): ?Minn\Content\PostRecord#
$rowarray<string, mixed>|null
privateids(array $ids): array#
$idslist<int>@return list<int> the positive ids, once each
privatebyName(string $name, array $types, string $status): ?Minn\Content\PostRecord#
$typeslist<string>
privatebyPath(array $segments, string $status): ?Minn\Content\PostRecord#
$segmentslist<string>
privatereadTerms(int $postId, string $taxonomy): array#
@return list<array{0: int, 1: string}>
privaterevisions(int $postId): array#
@return array{0: int, 1: int} how many revisions a post has, and the latest one's id (newest by date then id), or 0
privatereadRevisions(array $postIds): array#

Revision counts and latest ids for many posts in one query.

$postIdslist<int>
@return array<int, array{0: int, 1: int}>
privateweekMode(): int#

MySQL's WEEK() mode for the site's first day of the week: 0 for Sunday, 1 for Monday.

privatemonthBeside(string $type, string $clause, string $edge): ?array#
@return array{int, int}|null