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.
Used by 42 (show)
Constants and properties
| private | readonly Minn\Db $db | Promoted from the constructor. |
Public
| new | __construct(Minn\Db $db)# | |||||||
| method | find(int $id): ?Minn\Content\PostRecord# | The post with this id, or null. | ||||||
| method | prime(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.
| ||||||
| method | rememberRows(array $rows): void# | Keeps rows a query already read (WP_Query's whole posts), so priming those posts reads them no second time.
| ||||||
| method | primeRows(array $ids): void# | Reads the rows of the posts not read yet, in one query. @param list<int> $ids
| ||||||
| method | primeMeta(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
| ||||||
| method | primeTerms(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.
| ||||||
| method | findByName(string $name, array $types): ?Minn\Content\PostRecord# | The post with this slug among the given types; published only unless asked otherwise.
| ||||||
| method | findByNameAnyStatus(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
| ||||||
| method | byOldSlug(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).
| ||||||
| method | pageByPath(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.
| ||||||
| method | pageByPathAnyStatus(array $segments): ?Minn\Content\PostRecord# | The page at a slug path in any status but trash, or null. @param list<string> $segments
| ||||||
| method | byTypedPath(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.
| ||||||
| method | pathOf(Minn\Content\PostRecord $page): string# | The slash-joined ancestry of a page: "sample-page/docs". | ||||||
| method | guess(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.
| ||||||
| method | hasPublished(string $type): bool# | Whether any post of a type is published. | ||||||
| method | idsOfType(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> | ||||||
| method | meta(int $postId, string $key): ?string# | One meta value of a post, or null when it has none. | ||||||
| method | terms(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 | ||||||
| method | revisionCount(int $postId): int# | How many revisions the post has. | ||||||
| method | primeRevisions(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).
| ||||||
| method | latestRevisionId(int $postId): int# | The latest revision id, an autosave counting as one, newest by date then id (probe rest-latest-revision), or 0. | ||||||
| method | hasNewerAutosave(int $postId, string $modifiedGmt): bool# | Whether a live post carries an autosave newer than its saved state. | ||||||
| method | newest(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.
| ||||||
| method | daysWithPosts(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> | ||||||
| method | archiveBuckets(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}> | ||||||
| method | adjacentClauses(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").
@return array{0: string, 1: string, 2: string} | ||||||
| method | adjacentId(string $join, string $where, string $sort): int# | The post the clauses find (as their filters left them), or 0. | ||||||
| method | archiveList(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> | ||||||
| method | monthBefore(int $year, int $month, string $type): ?array# | The nearest month before one with a published post of a type, as [year, month], or null. | ||||||
| method | monthAfter(int $year, int $month, string $type): ?array# | The nearest month after one with a published post of a type, as [year, month], or null. | ||||||
| method | newestAutosave(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. | ||||||
| method | firstCategorySlug(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.
| private | record(?array $row): ?Minn\Content\PostRecord# |
| |||
| private | ids(array $ids): array# |
| |||
| private | byName(string $name, array $types, string $status): ?Minn\Content\PostRecord# |
| |||
| private | byPath(array $segments, string $status): ?Minn\Content\PostRecord# |
| |||
| private | readTerms(int $postId, string $taxonomy): array# | @return list<array{0: int, 1: string}> | |||
| private | revisions(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 | |||
| private | readRevisions(array $postIds): array# | Revision counts and latest ids for many posts in one query.
@return array<int, array{0: int, 1: int}> | |||
| private | weekMode(): int# | MySQL's WEEK() mode for the site's first day of the week: 0 for Sunday, 1 for Monday. | |||
| private | monthBeside(string $type, string $clause, string $edge): ?array# | @return array{int, int}|null |
Nothing matches.