Skip to main content

Delete

Permanently deletes a post, media file, or category from WordPress.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Client Id - The client ID from the Connect node (optional if using direct credentials).
  • Object Id - The ID of the object to delete (post ID, media ID, or category ID).

Options

  • Object - Type of object to delete. Required. Options:
    • Post - Delete a post
    • Media - Delete a media file
    • Category - Delete a category
  • Site URL - (Optional) WordPress site URL. Use this if you want to authenticate directly without a Connect node.
  • Credentials - (Optional) WordPress username and application password. Use this if you want to authenticate directly without a Connect node.

How It Works

The Delete node permanently removes a WordPress object using the WordPress REST API.

When executed, the node:

  1. Validates the Object type is selected
  2. Validates the Object Id is provided
  3. Retrieves the authentication (either from Client Id or direct credentials)
  4. Sends a DELETE request to /wp-json/wp/v2/{object_type}/{id} endpoint
  5. For categories and media, automatically sets force=true to bypass trash
  6. Permanently deletes the object

Authentication Methods

Connect → Store Client Id → Delete (use Client Id)

Method 2: Direct Credentials

Provide both Site URL and Credentials directly in the node options.

Requirements

  • A WordPress site with REST API enabled (WordPress 4.7+)
  • Valid object ID that exists
  • Appropriate user permissions:
    • To delete posts: author role or higher (must be post author or editor/admin)
    • To delete media: author role or higher (must be uploader or editor/admin)
    • To delete categories: editor role or higher
  • Object must exist before deletion

Deletion Behavior

Post Deletion

  • Posts are moved to trash by default
  • Can be restored from trash in WordPress admin
  • Trash is emptied after 30 days (default WordPress setting)

Media Deletion

  • Media files are permanently deleted (force=true)
  • File is removed from server storage
  • Cannot be recovered after deletion
  • Any posts using this media will have broken links

Category Deletion

  • Categories are permanently deleted (force=true)
  • Posts in the deleted category are moved to "Uncategorized"
  • Cannot be recovered after deletion
  • Subcategories become orphaned or move up in hierarchy
warning

Deletion is permanent for media and categories. For posts, they go to trash first but are permanently deleted after 30 days. Always verify before deleting.

Error Handling

The node will return specific errors in the following cases:

  • Object type not selected
  • Empty or missing Object Id
  • Invalid Object Id (object doesn't exist)
  • Authentication failure
  • Insufficient permissions to delete object
  • Category is default "Uncategorized" (cannot be deleted)
  • Network connection errors
  • WordPress REST API disabled

Usage Notes

  • Deletion is immediate and cannot be undone (except posts in trash)
  • Always verify the Object Id before deleting
  • Consider archiving instead of deleting for important content
  • Media deletion removes files from server - check usage before deleting
  • Category deletion reassigns posts to "Uncategorized"
  • Cannot delete the default "Uncategorized" category
  • No output is returned on successful deletion

Example: Delete Post

Inputs:

  • Object Id: 123

Options:

  • Object: Post

This moves the post to trash (can be restored within 30 days).

Example: Delete Media File

Inputs:

  • Object Id: 456

Options:

  • Object: Media

This permanently deletes the media file from the server.

Example: Delete Category

Inputs:

  • Object Id: 5

Options:

  • Object: Category

This permanently deletes the category. Posts in this category are moved to "Uncategorized".

Common Use Cases

Content Cleanup

  • Remove old or outdated posts
  • Delete duplicate content
  • Clean up test posts
  • Remove spam content

Media Library Management

  • Delete unused media files
  • Clean up old images
  • Remove duplicates
  • Free up server storage

Category Maintenance

  • Remove unused categories
  • Clean up duplicate categories
  • Reorganize category structure
  • Delete test categories

Bulk Deletion

  • Remove posts older than a certain date
  • Delete posts by specific author
  • Clean up imported test data
  • Remove posts from specific categories

Automated Cleanup

  • Delete temporary content
  • Remove expired posts
  • Clean up draft posts
  • Automated archival workflows

Example Workflows

Delete Unused Media

1. List Media
2. For each media item:
- Check if used in any post (search posts for media.source_url)
- If not used:
- Delete (Object: Media, Object Id: media.id)
- Log deleted media

Delete Old Draft Posts

1. List Posts (Status: Draft)
2. For each post:
- Check post age (parse date)
- If older than 1 year:
- Delete (Object: Post, Object Id: post.id)
- Log deletion

Safe Category Deletion

1. Get (Object: Category, Object Id: category_id)
2. Check category.count (number of posts)
3. If count === 0:
- Delete (Object: Category, Object Id: category_id)
Else:
- Warn: Category has posts
- Move posts to different category
- Then delete

Bulk Post Deletion with Confirmation

1. List Posts (filter by criteria)
2. Display post count and details
3. Wait for manual confirmation
4. If confirmed:
- For each post:
- Delete (Object: Post, Object Id: post.id)
5. Generate deletion report

Delete Post and Associated Media

1. Get (Object: Post, Object Id: post_id)
2. Extract featured_media ID
3. Delete (Object: Post, Object Id: post_id)
4. If featured_media exists:
- Delete (Object: Media, Object Id: featured_media)

Pre-Deletion Checks

Verify Post Before Deletion

// After Get node retrieves post
const post = msg.object;

// Check conditions
const canDelete =
post.status === "draft" &&
post.date < one_year_ago &&
post.comment_count === 0;

if (canDelete) {
return { should_delete: true, post_id: post.id };
} else {
return { should_delete: false, reason: "Post doesn't meet criteria" };
}

Verify Media Not In Use

// Check if media is used
const media_url = msg.media.source_url;
const posts = msg.all_posts; // From List Posts

const usedInPost = posts.some(post =>
post.content.rendered.includes(media_url) ||
post.featured_media === msg.media.id
);

return {
can_delete: !usedInPost,
media_id: msg.media.id
};

Best Practices

  • Always verify the object exists before attempting deletion
  • Create backups before bulk deletions
  • Log all deletion operations for auditing
  • Implement confirmation steps for important deletions
  • Check for dependencies before deleting (e.g., media used in posts)
  • Use draft/private status instead of deletion when possible
  • Test deletion logic on staging environment first
  • Implement rollback procedures where possible
  • Handle deletion errors appropriately
  • Consider archiving instead of permanent deletion

Safety Measures

Implement Confirmation

1. Get object to delete
2. Display object details
3. Require manual confirmation or approval
4. Only then proceed with deletion

Create Backup Before Deletion

1. Get object
2. Export to JSON/CSV (backup)
3. Store backup in safe location
4. Then proceed with deletion

Soft Delete Alternative

Instead of deleting, update status:

Update (Object: Post, Object Id: post_id, Object: {
"status": "private",
"meta": { "marked_for_deletion": true, "deletion_date": date }
})

Recovery Options

For Posts (Trash)

  • Posts go to trash first
  • Can be restored from WordPress admin
  • Permanently deleted after 30 days
  • Cannot be recovered programmatically via REST API

For Media and Categories

  • Permanent deletion - no trash
  • Cannot be recovered
  • Must restore from backups
  • Prevention is the only option

Performance Considerations

  • Deletion is a fast operation
  • Bulk deletions should be throttled
  • Media deletion may take longer (file removal)
  • No significant server load for small batches
  • Large bulk deletions should be scheduled

Troubleshooting

Error: "Object should be selected"

  • Select Post, Media, or Category from the Object dropdown
  • The Object option is required

Error: "Object ID cannot be empty"

  • Provide a valid numeric Object Id
  • Verify the ID variable contains a value

Error: 404 Not Found

  • The object with that ID doesn't exist
  • Object may have already been deleted
  • Verify the ID is correct

Error: 403 Forbidden

  • Insufficient permissions to delete
  • Authors can only delete their own posts
  • Only editors+ can delete others' posts/media
  • Only editors+ can delete categories

Error: Cannot delete default category

  • WordPress prevents deletion of "Uncategorized"
  • Choose a different category to delete

Deletion succeeds but object still visible:

  • Posts go to trash (not permanently deleted)
  • Check WordPress admin trash
  • Empty trash to permanently delete
  • Refresh to see changes

Integration Examples

Cleanup Old Content

1. List Posts (Status: Publish)
2. Filter posts older than 2 years
3. For each old post:
- Check views/engagement (from analytics)
- If low engagement:
- Delete (Object: Post, Object Id: post.id)
- Log deletion
4. Generate cleanup report

Media Library Optimization

1. List Media
2. Calculate total storage used
3. For each media:
- Check file size
- Check usage in posts
- If large AND unused:
- Delete (Object: Media, Object Id: media.id)
- Track freed space
4. Report storage saved

Category Consolidation

1. List Categories
2. Identify similar/duplicate categories
3. For duplicate category:
- List Posts in category
- Update posts to use main category
- Delete (Object: Category, Object Id: duplicate.id)
4. Report consolidated categories

Automated Content Expiration

Schedule daily:
1. List Posts with custom field "expiry_date"
2. For each post:
- Check if expiry_date < today
- If expired:
- Delete (Object: Post, Object Id: post.id)
- Send notification
  • Check content retention policies before deletion
  • Some industries require content archival
  • Maintain deletion logs for compliance
  • Consider GDPR right to deletion
  • Archive important content before deletion
  • Document deletion procedures
  • Implement approval workflows for deletions

Deletion vs Alternatives

Consider alternatives to deletion:

  1. Change Status - Set to private or draft
  2. Archive Category - Move to "Archive" category
  3. Mark as Outdated - Add metadata without deleting
  4. Export Then Delete - Backup before removal
  5. Schedule Deletion - Mark for later deletion with review

When to delete:

  • Duplicate content
  • Test data
  • Spam content
  • Outdated time-sensitive content
  • Unused media files
  • Truly unnecessary categories

When NOT to delete:

  • Content with high traffic
  • Posts with comments/engagement
  • Historical reference content
  • Legal requirement to retain
  • Linked from external sites
  • Without proper backup