AI Blog Post Automation: PostgreSQL to WordPress - n8n Workflow

This powerful n8n workflow automates content creation using OpenAI, fetching topics from PostgreSQL and publishing SEO-optimized blogs directly to WordPress. Easily deploy this n8n template.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Content teams looking to scale blog production automatically.

  • Developers needing to bridge database data (PostgreSQL) with publishing platforms (WordPress).

  • Users seeking advanced n8n templates integrating AI agents and database synchronization.

  • Marketing professionals wanting to leverage the power of an n8n workflow for continuous SEO content generation.

Overview

Managing content pipelines often involves manual stepsโ€”transferring data from a planning table to a generation tool, and then manually posting the results. This advanced n8n workflow solves this by creating a fully automated, end-to-end publishing pipeline.

The system is initiated by an n8n trigger on a schedule, which checks a designated PostgreSQL table for new, unprocessed blog topics. When a topic is found, an OpenAI large language model (LLM) agent generates a comprehensive, SEO-optimized blog post, formatted into a strict JSON payload. The subsequent n8n node structures this data safely, ensuring all necessary metadata (like tags and categories) is present. Finally, the content is published to WordPress, and the original PostgreSQL record is updated, marking the entry as processed and storing the published URL.

This robust n8n automation ensures high efficiency, rapid content deployment, and synchronization between your database and live site, serving as a critical asset among powerful n8n templates.

How it Works

This n8n workflow operates in four primary stages:


  1. Scheduled Polling: The process begins with the โฐ Schedule Trigger, initiating the workflow at set intervals. The subsequent ๐Ÿ—„๏ธ PostgreSQL Trigger n8n node queries the database for the oldest unprocessed record where "Processed" = FALSE.

  2. Record Validation: The ๐Ÿ” Check Record Exists n8n node uses an If condition to ensure that the retrieved record is valid and contains a Blog_Title before committing resources to AI generation.

  3. AI Generation and Structuring: The system uses an OpenAI Chat Model to power the ๐Ÿค– Generates Blog Post agent. This n8n node utilizes a detailed system prompt instructing the AI to output a full, marketing-focused blog post (with title, content, excerpt, and meta description) strictly as JSON, based on the PostgreSQL title input.

  4. Data Preparation and Publishing: The ๐Ÿ“ Format Blog Data n8n node (a Code node) handles the crucial task of parsing the AI's JSON output, providing fallback text if parsing fails, and creating a clean structure for WordPress, including default categories and tags. The โœ๏ธ WordPress Publisher n8n node then publishes this content.

  5. Synchronization: Upon successful publishing, the ๐Ÿ’พ Update Database n8n node updates the original PostgreSQL record, setting Processed = TRUE and recording the WordPress post ID and URL. This ensures the n8n workflow does not process the same record again.

Installation Guide

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


  1. Import the n8n Workflow: Copy the provided JSON code and import it into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option.

  2. PostgreSQL Credentials: You must create or select existing PostgreSQL credentials. Update the connection ID in the ๐Ÿ—„๏ธ PostgreSQL Trigger and ๐Ÿ’พ Update Database n8n node settings.

  3. PostgreSQL Table Setup: In the PostgreSQL n8n nodes, replace "yourtablename" with your actual table name. Ensure your table has columns like Blog_Title, Processed (BOOLEAN), and id.

  4. OpenAI Credentials: Set up your OpenAI API credentials and link them to the OpenAI Chat Model n8n node.

  5. WordPress Credentials: Configure your WordPress API credentials (Application Passwords are recommended) and attach them to the โœ๏ธ WordPress Publisher n8n node.

  6. Configuration: Customize the scheduling interval in the โฐ Schedule Trigger and review the prompt in the ๐Ÿค– Generates Blog Post n8n node to match your specific content voice and style. This completes the setup of your new n8n automation.

Node Details

โฐ Schedule Trigger (n8n trigger): Initiates the entire n8n workflow based on a defined time interval.
๐Ÿ—„๏ธ PostgreSQL Trigger (n8n node): Executes a query (SELECT FROM "yourtablename" WHERE "Processed" = FALSE... LIMIT 1;) to fetch the single most recent unprocessed topic from the database.
๐Ÿ” Check Record Exists (If n8n node): A core flow control mechanism. It checks if the PostgreSQL result contains a valid record ID and a BlogTitle before moving to the expensive AI generation step.
๐Ÿค– Generates Blog Post (LangChain Agent n8n node): Takes the title as input and uses the linked OpenAI model (GPT-4o mini recommended) to generate a full blog post, strictly formatted in JSON. This is where the AI heavy lifting occurs within the n8n workflow.
๐Ÿ“ Format Blog Data (Code n8n node): This highly customized n8n node contains JavaScript logic to parse the potentially messy AI output, extract the required fields, implement safety fallbacks if JSON parsing fails, and construct the final payload with hardcoded tags (e.g., AI, WordPress) and categories.
โœ๏ธ WordPress Publisher (n8n node): Publishes the content. Key configurations include setting the status to 'publish' and dynamically mapping the title, content, excerpt, and the metadescription property via the 'Meta' section of the 'Additional Fields'.
๐Ÿ’พ Update Database (PostgreSQL n8n node): Executes an UPDATE query to synchronize the database. It uses parameters ($1, $2, etc.) mapped from the WordPress n8n node output (Post ID, URL) and the original record ID.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

๐Ÿš€ Founder of iTechNotion โ€” we build custom AI-powered automation workflows for startups, agencies, and founders. ๐Ÿ’ก Specializing in agentic AI systems, content automation, sales funnels, and digital workers. ๐Ÿ”ง 14+ years in tech | Building scalable no-code/low-code solutions using n8n, OpenAI, and other API-first tools. ๐Ÿ“ฌ Letโ€™s automate what slows you down.

Featured*