wp_delete_post
Delete WordPress posts permanently or move them to trash. Specify a post ID and choose between trash or force deletion for content management.
Instructions
Deletes a WordPress post with options for trash or permanent deletion. Includes safety confirmations and detailed feedback on the deletion action.
Usage Examples:
• Trash a post: wp_delete_post --id=123 (moves to trash)
• Permanent deletion: wp_delete_post --id=123 --force=true
• Bulk operations: Use multiple calls with different IDs
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | The ID of the WordPress site to target (from mcp-wordpress.config.json). Required if multiple sites are configured. | |
| id | Yes | The ID of the post to delete. | |
| force | No | Whether to bypass trash and force deletion (default: false, moves to trash). |
Implementation Reference
- src/tools/posts/PostHandlers.ts:411-442 (handler)Core handler function that executes the wp_delete_post tool logic: validates the post ID, calls WordPressClient.deletePost (with optional force for permanent delete vs trash), formats success response with details or handles specific errors like 404.export async function handleDeletePost( client: WordPressClient, params: { id: number; force?: boolean }, ): Promise<{ deleted: boolean; previous?: WordPressPost } | string> { try { const postId = validateId(params.id, "post ID"); const result = await client.deletePost(postId, params.force); if (result.deleted) { const action = params.force ? "permanently deleted" : "moved to trash"; let response = `✅ **Post ${action} successfully**\n\n`; if (result.previous) { response += `**Title**: ${result.previous.title.rendered}\n`; response += `**ID**: ${result.previous.id}\n`; } if (!params.force) { response += `\n**Note**: Post moved to trash. Use \`force=true\` to permanently delete.`; } return response; } else { return `Failed to delete post with ID ${params.id}. It may not exist or you may not have permission.`; } } catch (_error) { if (_error instanceof Error && _error.message.includes("404")) { return `Post with ID ${params.id} not found. Please verify the ID and try again.`; } throw new Error(`Failed to delete post: ${getErrorMessage(_error)}`); } }
- src/tools/posts/index.ts:232-246 (handler)PostTools class method that acts as the bound handler for wp_delete_post, extracts and type-casts input parameters from MCP call, then delegates to the core handleDeletePost implementation.public async handleDeletePost( client: WordPressClient, params: { id: number; force?: boolean } | Record<string, unknown>, ): Promise<{ deleted: boolean; previous?: WordPressPost } | string> { // Extract only the relevant parameters const deleteParams: { id: number; force?: boolean } = { id: params.id as number, }; if (params.force !== undefined) { deleteParams.force = params.force as boolean; } return handleDeletePost(client, deleteParams); }
- MCPTool schema definition for wp_delete_post including name, detailed description with usage examples, and inputSchema specifying required 'id' (number) and optional 'force' (boolean).export const deletePostTool: MCPTool = { name: "wp_delete_post", description: "Deletes a WordPress post with options for trash or permanent deletion. Includes safety confirmations and detailed feedback on the deletion action.\n\n" + "**Usage Examples:**\n" + "• Trash a post: `wp_delete_post --id=123` (moves to trash)\n" + "• Permanent deletion: `wp_delete_post --id=123 --force=true`\n" + "• Bulk operations: Use multiple calls with different IDs", inputSchema: { type: "object", properties: { id: { type: "number", description: "The ID of the post to delete.", }, force: { type: "boolean", description: "Whether to bypass trash and force deletion (default: false, moves to trash).", }, }, required: ["id"], }, };
- src/tools/posts/index.ts:90-107 (registration)Registration of wp_delete_post handler in PostTools.getHandlerForTool switch statement: maps tool name to this.handleDeletePost method, which is then attached during getTools() for MCP tool registration.private getHandlerForTool(toolName: string) { switch (toolName) { case "wp_list_posts": return this.handleListPosts.bind(this); case "wp_get_post": return this.handleGetPost.bind(this); case "wp_create_post": return this.handleCreatePost.bind(this); case "wp_update_post": return this.handleUpdatePost.bind(this); case "wp_delete_post": return this.handleDeletePost.bind(this); case "wp_get_post_revisions": return this.handleGetPostRevisions.bind(this); default: throw new Error(`Unknown tool: ${toolName}`); } }