The PostsService allows you to manage WordPress posts. It supports creating, reading, updating, and deleting posts.
Access via the facade:
$postsService = $wp->posts();Retrieve a paginated collection of posts.
$posts = $wp->posts()->list([
'per_page' => 10,
'status' => 'publish',
'categories' => [1, 2] // Filter by category IDs
]);
foreach ($posts as $post) {
echo $post->title->rendered;
}use JooServices\WordPress\Sdk\Exceptions\NotFoundException;
try {
$post = $wp->posts()->get(123);
echo $post->content->rendered;
} catch (NotFoundException $e) {
echo "Post not found.";
}$post = $wp->posts()->create([
'title' => 'New Post Title',
'content' => 'Post content goes here.',
'status' => 'draft',
'categories' => [5]
]);$updatedPost = $wp->posts()->update(123, [
'title' => 'Updated Title'
]);By default, deleting a post sends it to the Trash.
$trashedPost = $wp->posts()->delete(123);To permanently delete a post:
$deletedPost = $wp->posts()->delete(123, force: true);- ContentBuilder: generate complex post content programmatically.
- Templates: create posts using structured templates.