AbstractPost
Abstract class.
The object of a post: a class with #[PostType] extends it, and the framework
provides Post and Page for the post types of WordPress.
A post object is loaded with Event::get($id) or Event::find($id) and created
with new Event(). It holds the data of the post (title, content, status, …) and
its meta objects (meta(EventDetails::class)); save() checks every meta value
against its schema and writes the post and the changed meta values.
Every get() and find() returns a new object; changes are visible to others only after save(). save() checks no capabilities, like wp_update_post().
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