Automated SEO Article Generation and WordPress Publishing with GPT and PostgreSQL - n8n Workflow

Automate SEO article publishing to WordPress using this powerful n8n workflow. It integrates GPT-4 for content generation, PostgreSQL for intelligent category tracking, and handles media uploads.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Content marketers looking to scale blog production without manual effort.
SEO specialists needing an automated way to cover long-tail keywords and balance category usage.
Developers seeking advanced n8n templates integrating databases (Postgres) and large language models (OpenAI).
Blog owners requiring scheduled, high-quality content delivery.

Overview

This sophisticated automation solves the problem of manual content creation and repetitive category selection for large-scale blogging operations. It uses the power of an n8n workflow scheduled to run periodically. The core intelligence lies in its ability to analyze existing WordPress categories, check usage statistics stored in PostgreSQL, and then select the least-used topic to ensure broad SEO coverage.

Once a topic is chosen, the n8n node sends requests to GPT-4 for generating a highly structured article (complete with WordPress HTML blocks, TOC, and CTA) and even generates a placeholder image. The entire process—from idea generation and database logging to media upload and final publication—is handled seamlessly by this powerful n8n workflow, making it one of the most comprehensive n8n templates available for content automation.

How it Works

The process begins with the Schedule Trigger n8n trigger, initiating the automation based on a set interval (e.g., hourly).


  1. Category Selection: The workflow first retrieves all available WordPress categories via an HTTP Request. It filters out unwanted IDs and then queries the PostgreSQL database to determine which category has been used least recently.

  2. Topic Generation: Using the selected category details and the titles of the 10 most recent posts (fetched from Postgres), the AI Agent SEO Headings n8n node, powered by GPT-4-mini, generates a highly unique, non-duplicative article title.

  3. Tracking & Logging: The workflow immediately logs the newly chosen title and category ID into the PostgreSQL usedcategories table using an 'upsert' operation. This ensures the category won't be reused immediately in the next cycle, enhancing the SEO strategy.

  4. Content Generation: The AI Agent SEO writer n8n node, powered by GPT-4, generates the complete article text. This prompt is carefully configured to output content strictly in native WordPress HTML block format, ensuring compatibility and structure (including a Table of Contents).

  5. Media Handling: While the content is generated, another branch creates a temporary image URL using the category name, downloads it, and uploads it via the WordPress REST API, obtaining the necessary featuredmedia ID.

  6. Publication: All generated components (content, featured media ID, title, and category ID) are merged into a final JSON payload. The Post to WP HTTP Request n8n node then publishes the new article with a 'publish' status to the WordPress site, completing the n8n workflow execution.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code and paste it into your n8n instance using the 'Import from JSON' option.

  2. Environment Configuration: Locate the Config n8n node. Change the domain assignment value to your actual WordPress site URL (e.g., https://yourdomain.com).

  3. PostgreSQL Setup: Before running the workflow, you must set up the tracking database. Create a database (e.g., n8nblog) and a user with write privileges. Crucially, create the public.usedcategories table with columns: categoryid (INTEGER PRIMARY KEY), name (TEXT), description (TEXT), title (TEXT), and usedat (TIMESTAMPTZ).

  4. Credential Setup:

Postgres: Create an n8n credential named YOURPOSTGRESCREDENTIAL linking to your newly configured database.
OpenAI: Create an n8n credential named YOUROPENAICREDENTIAL for the GPT-4 nodes.
* WordPress: Create an n8n credential named Wordpress account (or similar, matching the connection in the HTTP Request nodes) with API access rights (POST /media, POST /posts).

  1. Execution: Ensure all credentials are set up correctly. Run the n8n workflow manually once to verify all connections (Postgres, OpenAI, WordPress) before activating the Schedule Trigger n8n trigger for full automation.

Node Details

Schedule Trigger: The starting n8n trigger point. Configured to run at regular intervals (e.g., every few hours) to maintain continuous content flow.
Config (Set): A setup n8n node used to define the base WordPress domain, which is referenced dynamically throughout the n8n workflow's HTTP Requests.
Load Categories (HTTP Request): Fetches categories from the WordPress REST API. Essential for category filtering and selection.
Category Filter (Code): A critical n8n node that defines which category IDs should be ignored by the AI agent (e.g., generic or review categories).
Selecting recent (Postgres): Executes a query to find the lastusedat timestamp for all categories in the database, enabling the intelligent category rotation strategy.
Picks Less Used (Code): This logic n8n node compares the last used time of available categories and selects the one with the oldest timestamp, ensuring content diversity.
AI Agent SEO Headings (Langchain Agent): Uses GPT-4-mini for rapid title generation. The prompt leverages existing recent titles to guarantee the new title is unique and SEO-focused.
AI Agent SEO writer (Langchain Agent): The main content generation n8n node. Uses GPT-4 to generate complex, structured content conforming to specific WordPress block requirements, ensuring the published post is clean and highly formatted.
Updating posts DB (Postgres): An Upsert operation that tracks the new article title and marks the category as 'used now' in the PostgreSQL database.
Media Upload to WP (HTTP Request): Uploads the placeholder image file retrieved by the Download Image n8n node directly to the WordPress media library, generating the featured_media ID needed for publication.
Prepare Post JSON (Code): The final transformation n8n node, consolidating the category ID, featured media ID, GPT-generated content, and new title into the correct structure for the WordPress API.
Post to WP (HTTP Request): The final action n8n node, publishing the complete, SEO-ready article to the configured WordPress site.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by
AlexWantMoreB
AlexWantMoreB

Automation consultant helping growth teams, agencies, and founders scale with AI + no-code. I specialize in building GPT-powered content systems, lead gen automations, and PostgreSQL-enhanced flows. 📬 Book custom n8n work or DM for collabs.

Featured*