Moves a draft post with the provided ID to the trash bin.
A published post can also be deleted by its provided draftPostId
.
The optional permanent
field enables you to delete a post permanently, bypassing the trash bin. When a draft post is deleted this way, it can't be restored.
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function deleteDraftPost(
draftPostId: string,
options: DeleteDraftPostOptions,
): Promise<void>;
Draft post ID.
Options for deleting a draft post.
import { draftPosts } from "wix-blog-backend";
import { webMethod, Permissions } from "wix-web-module";
import { elevate } from "wix-auth";
// Sample draftPostId value: "2b36fbd0-f87a-43ce-ad11-e73d354b0072"
const elevatedDeleteDraftPost = elevate(draftPosts.deleteDraftPost);
export const myDeleteDraftPostFunction = webMethod(
Permissions.Admin,
async (draftPostId) => {
try {
await elevatedDeleteDraftPost(draftPostId);
console.log(
"Successfully deleted the following draft post:",
draftPostId,
);
return;
} catch (error) {
console.error(error);
// Handle the error
}
},
);
// Promise returns void
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.