Post
Class. It extends AbstractPost.
A post of the post type post of WordPress. Meta classes and taxonomies of a theme or
plugin name it in postTypes: [Post::class].
Constructor
Creates a new post of the type; it is stored by save().
Methods
find()
The post with the ID, in any status; null if it does not exist or has another post type.
Returns ?AbstractPost
get()
The post with the ID, in any status.
Returns AbstractPost
Throws InvalidArgumentException: If it does not exist or has another post type.
query()
A query for posts of the type: published posts, unsorted conditions, see PostQuery.
Returns PostQuery<AbstractPost>
delete()
Moves the post to the trash, or deletes it permanently with $force. WordPress moves only posts and pages to the
trash (and only while the trash is enabled, EMPTY_TRASH_DAYS); posts of other types and posts already in the
trash are deleted permanently either way.
Throws LogicException: If the post has not been saved.
Throws RuntimeException: If WordPress cannot delete the post.
getAuthorId()
The ID of the author, null without author.
Returns ?int
getContent()
The content as stored: block markup.
Returns string
getDate()
The publication date in UTC, null for posts without one (drafts).
Returns ?DateTimeImmutable
getExcerpt()
The manual excerpt as stored; empty without one.
Returns string
getId()
The ID, null before the post has been saved.
Returns ?int
getModified()
The date of the last change in UTC, null before the post has been saved.
Returns ?DateTimeImmutable
getParent()
The parent post (hierarchical post types), null without parent.
Returns ?AbstractPost
getSlug()
The slug (post_name), empty until WordPress assigns one.
Returns string
getStatus()
The status; a new post is a draft.
Returns PostStatus
getTerms()
The terms of a taxonomy (a class with #[Taxonomy]), as stored; changes by setTerms() count after save().
Returns list<WP_Term>: The terms; empty before the post has been saved.
getTitle()
The title as stored, or as set by setTitle() before save().
Returns string
getUrl()
The permalink, null before the post has been saved.
Returns ?string
meta()
The meta object of a meta class (#[PostMeta] naming this post class), loaded on first use; the same object
until the post object is gone. In templates the meta class is named by its #[PostMeta] name:
post.meta('details').
Returns ($class is class-string<T> ? T : object)
save()
Stores the post: checks the loaded meta objects against their schemas (nothing is written if a value is invalid), inserts or updates the post and writes the changed meta values and terms.
Throws PostValidationException: If a meta value is invalid.
Throws RuntimeException: If WordPress cannot save the post.
setAuthorId()
Sets the author; stored by save().
setContent()
Sets the content; stored by save().
setExcerpt()
Sets the manual excerpt; stored by save().
setParent()
Sets the parent post (hierarchical post types); stored by save().
Throws LogicException: If the post type is not hierarchical.
Throws InvalidArgumentException: If the parent has another class or has not been saved.
setSlug()
Sets the slug (post_name); stored by save().
setStatus()
Sets the status; stored by save(). The capabilities of the current user are not checked.
setTerms()
Sets the terms of a taxonomy (a class with #[Taxonomy]); stored by save(), replacing the terms the post had.
setTitle()
Sets the title; stored by save().
toWpPost()
The WordPress post, null before the post has been saved.
Returns ?WP_Post