Automated WordPress Post and Featured Image Deletion - n8n Workflow

Streamline WordPress site maintenance using this powerful n8n workflow template. Automatically fetch and delete 'pending' posts and their corresponding featured images using custom n8n node configuration.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

WordPress Site Administrators requiring an automated maintenance n8n solution.
Content Managers needing to implement a rigorous post rejection and cleanup process.
Technical users seeking advanced n8n templates for interacting with external APIs via HTTP requests.
Anyone looking for an efficient batch deletion solution built using the low-code power of n8n.

Overview

Managing high volumes of content often results in clutter, particularly posts stuck in statuses like 'pending review'. Manually deleting these posts and ensuring their featured media files are also removed can be a tedious and error-prone task. This custom n8n workflow solves this by providing a hands-free method to systematically query your WordPress site for posts matching specific criteria (e.g., status: pending) and performing a forced deletion of both the post and its associated featured image. This particular n8n workflow is designed for high scalability, ensuring your WordPress database remains clean. The core of this n8n solution leverages the HTTP Request n8n node for seamless API communication, making it a highly valuable addition to your n8n templates library.

How it Works

This automation starts with the 'Change your Domain here' n8n trigger node, which is a Manual Trigger used here to set the base URL for the WordPress installation.


  1. Retrieve Posts: The first HTTP Request n8n node ('get post') uses the configured domain to query the WordPress REST API (/wp/v2/posts) specifically filtering for posts with the status: pending parameter.

  2. Filter & Gate: A Filter n8n node is included, which, by default, restricts the processing to only the first item returned. This is often used when integrating with external approval systems (as noted in the sticky note). For true batch deletion of all retrieved posts, this filter n8n node should be disabled or removed.

  3. Conditional Check (Has Img): The workflow proceeds to an If n8n node ('Has Img'). This n8n node checks if the post has a featured_media ID greater than 0.

  4. Path A (Image Present): If a featured image exists, the workflow first uses an HTTP Request n8n node ('get img') to fetch the media details, followed by another HTTP Request n8n node ('delete img') configured with the DELETE method and force: true to permanently remove the media item. Finally, a subsequent HTTP Request n8n node ('delete post with img') deletes the main WordPress post, also using force: true.

  5. Path B (No Image): If no featured media is found, the workflow bypasses the image deletion steps and goes directly to the final HTTP Request n8n node ('delete post') to perform a forced DELETE operation on the WordPress post. This entire process defines a robust and conditional n8n workflow pattern.

Installation Guide

To deploy this powerful n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON code and paste it into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Configure URL: Locate the 'Change your Domain here' manual n8n trigger node. Update the wpUrl property to your specific WordPress domain (e.g., https://your-site.com).

  3. Set Credentials: The 'get post' n8n node (and all subsequent HTTP Request nodes) requires WordPress authentication. You must edit these nodes and configure appropriate Basic or Bearer Token credentials to allow the n8n workflow to interact with your site's REST API.

  4. Review Filters (Optional): If you intend to delete all pending posts retrieved in one run, locate the 'Filter' n8n node and disable it, as its default configuration limits the workflow to processing only one post item.

  5. Activate: Once configured, activate the n8n workflow and execute the 'Change your Domain here' n8n trigger to begin the process. This specific n8n workflow is designed for maintenance and cleanup.

Node Details

Change your Domain here (Manual Trigger n8n Trigger): Acts as the entry point and configures the wpUrl parameter needed by all subsequent HTTP Request n8n node steps.
get post (HTTP Request n8n node): Function: Queries the WordPress REST API for posts. Key Configuration: Targets the /wp/v2/posts endpoint and filters for status: pending.
Filter (Filter n8n node): Function: Currently restricts processing to the first item ($itemIndex < 1). For batch processing using this n8n template, this node should be removed.
Has Img (If n8n node): Function: Routes the workflow based on whether the post object contains a featured image ID (featured_media != 0).
delete img (HTTP Request n8n node): Function: Executes a forced DELETE request against the media endpoint, ensuring the featured image is permanently removed.
delete post (HTTP Request n8n node): Function: Executes a forced DELETE request against the post endpoint for items that did not have a featured image.


  • delete post with img (HTTP Request n8n node): Function: Executes a forced DELETE request against the post endpoint after its corresponding featured media has been successfully deleted.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Eric
Eric

Featured*