{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "4a331f37-25d1-4559-8152-915accafc292",
      "name": "Fetch One WordPress Blog",
      "type": "n8n-nodes-base.wordpress",
      "position": [
        -1392,
        -320
      ],
      "parameters": {
        "limit": 1,
        "options": {},
        "operation": "getAll"
      },
      "credentials": {
        "wordpressApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1417818e-358c-41a1-b5b9-29c23f3ca5c5",
      "name": "Execute",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1648,
        -320
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "4febde7b-ee54-498b-9e76-e49922b1f5d5",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -992,
        -144
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{\n\t\"tags\": [\"tag1\", \"tag2\", \"tag3\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "62ddc2a6-4066-4b4e-885c-40a40d174081",
      "name": "5-mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -992,
        16
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini",
          "cachedResultName": "gpt-5-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5914eacd-bd41-4b33-99ec-9de231313440",
      "name": "4.1 mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1104,
        16
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4e9af5e1-84c9-4048-b48e-cc760eec0429",
      "name": "Blog Tags Generator",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -1056,
        -320
      ],
      "parameters": {
        "text": "=Input:\n{{ $json.content.rendered }}",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "=You are a blog tag generator. Your sole purpose is to analyze blog content and output relevant tags.\n\nCRITICAL RULES:\n1. Output ONLY tags - no explanations, no introductions, no additional text\n2. Generate 5-10 relevant tags per blog post\n3. Tags should be:\n   - Specific and relevant to the content\n   - Mix of broad categories and specific topics\n   - Single words or short phrases (2-3 words max)\n   - SEO-friendly and commonly searched terms\n\nEXAMPLES:\nInput: \"Blog about machine learning in healthcare\"\nOutput: machine learning, healthcare, AI, medical technology, data science, predictive analytics, health tech\n\nInput: \"Blog about vegan recipes for beginners\"\nOutput: vegan recipes, plant-based, beginner cooking, healthy eating, vegetarian, meal prep, easy recipes\n\nDo not include:\n- Explanations of why you chose tags\n- Numbered lists\n- Bullet points\n- Any conversational text\n- Questions or confirmations\n\nSimply analyze the blog content provided and return only the comma-separated tags."
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "57746e58-1f54-4635-99ea-883fb1237f25",
      "name": "Update a post",
      "type": "n8n-nodes-base.wordpress",
      "position": [
        1248,
        -544
      ],
      "parameters": {
        "postId": "={{ $('Fetch One WordPress Blog').item.json.id }}",
        "operation": "update",
        "updateFields": {
          "tags": "={{ $json.id }}"
        }
      },
      "credentials": {
        "wordpressApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d7e0df80-d55c-47ab-b598-1cb14bff5eff",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        432,
        -544
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Old Tags",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "eb28b827-63d7-442d-aa0e-1a9c8ff47c1a",
                    "operator": {
                      "type": "number",
                      "operation": "notExists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.id }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "New Tags",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "38be9945-36d1-4f52-ac26-f54151bef5db",
                    "operator": {
                      "type": "number",
                      "operation": "exists",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.id }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "allMatchingOutputs": true
        },
        "looseTypeValidation": true
      },
      "typeVersion": 3.3
    },
    {
      "id": "ee934337-420f-4b1e-92b0-b0cd2d0f1c49",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1056,
        -544
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "id"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "365bc727-0da5-4c31-9bdf-8462f9000366",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        -448
      ],
      "parameters": {
        "color": 2,
        "width": 816,
        "height": 592,
        "content": "## \ud83c\udff7\ufe0f Tagging loop \n```It is responsible for Create Tag and if Tag is already exist it return only name.```"
      },
      "typeVersion": 1
    },
    {
      "id": "6e0b0f17-b019-4376-a6c0-80957e5e2a9e",
      "name": "Tagging Loop",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -384,
        -320
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7fdb28d6-b03a-4ab8-8447-e808e151269a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        -768
      ],
      "parameters": {
        "color": 6,
        "width": 448,
        "height": 272,
        "content": "## Fetch All Tags \ud83c\udff7\ufe0f"
      },
      "typeVersion": 1
    },
    {
      "id": "110e0624-a887-4f4b-a1bc-a5cde42f0cdf",
      "name": "Fetch All Tags",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -416,
        -688
      ],
      "parameters": {
        "url": "https://<your-website-domain>/wp-json/wp/v2/tags",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "per_page",
              "value": "100"
            }
          ]
        },
        "nodeCredentialType": "wordpressApi"
      },
      "credentials": {
        "wordpressApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "2ede6e29-fe54-4627-a4d1-63dd83cc1efa",
      "name": "Clean Data",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -224,
        -688
      ],
      "parameters": {
        "include": "selectedOtherFields",
        "options": {},
        "fieldToSplitOut": "id",
        "fieldsToInclude": "name"
      },
      "typeVersion": 1
    },
    {
      "id": "dce6daee-f068-49d1-be7a-677ddebf911d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1696,
        -432
      ],
      "parameters": {
        "color": 4,
        "width": 480,
        "height": 304,
        "content": "## 1. Fetch only one WordPress Blog(post)\n- ```Modify this according your use-case```"
      },
      "typeVersion": 1
    },
    {
      "id": "8d6dac98-895d-4a84-8835-9c123e7ebefb",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1168,
        -528
      ],
      "parameters": {
        "color": 2,
        "width": 624,
        "height": 688,
        "content": "## 2.  Give relevant tags\n```\ud83e\udd16 AI Decide which tags are perfect for Blog post. We use structure output parser here for desired output.``` "
      },
      "typeVersion": 1
    },
    {
      "id": "8da6b6c4-53f2-45c4-90da-07ce30c1b3b4",
      "name": "Split Out for Loop",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -704,
        -320
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output.tags"
      },
      "typeVersion": 1
    },
    {
      "id": "44d2cb4a-4e91-433b-9db0-ffec1fc0093c",
      "name": "Create New Tag",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        -144,
        -304
      ],
      "parameters": {
        "url": "https://<your-domain>/wp-json/wp/v2/tags",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json['output.tags'] }}"
            }
          ]
        },
        "nodeCredentialType": "wordpressApi"
      },
      "credentials": {
        "wordpressApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "7737d69e-8513-44f2-94f3-456bfce32f57",
      "name": "Return Tag ID & Name",
      "type": "n8n-nodes-base.set",
      "position": [
        96,
        -320
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "2e9b6565-3a9d-4389-b5bf-112bdf1af446",
              "name": "id",
              "type": "number",
              "value": "={{ $json.id }}"
            },
            {
              "id": "160e866a-6a17-4602-8ca6-88bc9b5ff3c0",
              "name": "name",
              "type": "string",
              "value": "={{ $json.name }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a6e79e80-7d5c-4ded-a140-301fd54ccc39",
      "name": "Return Name Only",
      "type": "n8n-nodes-base.set",
      "position": [
        112,
        -80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "bbd95b6f-c4fd-47a1-a3dc-b8e43d546bf0",
              "name": "name",
              "type": "string",
              "value": "={{ $json['output.tags'] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "550d6e4c-6dd1-400f-88b9-a5655bc19a3f",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        -784
      ],
      "parameters": {
        "color": 2,
        "width": 1104,
        "height": 448,
        "content": "## \u27bf Logic for label mapping\n```It map already exist Tag name to it's actual Tag ID```"
      },
      "typeVersion": 1
    },
    {
      "id": "441c8e33-fc40-4796-bbd8-640fdcc41f67",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        656,
        -672
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "fieldsToMatchString": "name"
      },
      "typeVersion": 3.2
    },
    {
      "id": "4495c184-8c4e-45d1-bac2-91a35df1af78",
      "name": "Merge Old and Mapped Tags",
      "type": "n8n-nodes-base.merge",
      "position": [
        880,
        -544
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "512c129e-c3a7-42d8-8b6b-55dc58d1124b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2400,
        -704
      ],
      "parameters": {
        "width": 544,
        "height": 816,
        "content": "## AI-Powered WordPress Blog Auto-Tagging\n\nThis workflow automates your SEO strategy by using AI to generate relevant tags for your WordPress posts. It includes intelligent logic to handle existing tags, ensuring you don't create duplicates (e.g., preventing \"AI\" and \"Ai\" from existing as separate tags).\n\n### How it works\n1. **Fetch Content:** The workflow retrieves a blog post from your WordPress site.\n2. **AI Analysis:** OpenAI analyzes the full text of the article and generates 5-10 SEO-friendly tags.\n3. **Database Check:** It fetches your existing WordPress tags to check for matches.\n4. **Smart Creation:**\n   * If a tag **does not exist**, it creates a new one via the API.\n   * If a tag **already exists**, it maps the name to the existing ID to prevent duplicates.\n5. **Update:** Finally, it updates the original blog post with the correct list of Tag IDs.\n\n### Setup steps\n1. **Credentials:** Configure your **WordPress (App Password)** and **OpenAI** credentials.\n2. **Update URLs:** Open the **Fetch All Tags** and **Create New Tag** nodes. Replace `https://your-domain` with your own WordPress domain.\n3. **Select Post:** By default, the trigger fetches the latest post. You can modify the \"Fetch One WordPress Blog\" node to target specific posts by ID if preferred.\n\n## Key features:\n- Structured AI output ensures consistent tag formatting\n- Loop-based processing handles multiple tags efficiently\n- Error handling for tag creation failures\n- Aggregates all tag IDs before final update"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Merge Old and Mapped Tags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5-mini": {
      "ai_languageModel": [
        [
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "Merge Old and Mapped Tags",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Execute": {
      "main": [
        [
          {
            "node": "Fetch One WordPress Blog",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4.1 mini": {
      "ai_languageModel": [
        [
          {
            "node": "Blog Tags Generator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Update a post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Data": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tagging Loop": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create New Tag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create New Tag": {
      "main": [
        [
          {
            "node": "Return Tag ID & Name",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return Name Only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch All Tags": {
      "main": [
        [
          {
            "node": "Clean Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Return Name Only": {
      "main": [
        [
          {
            "node": "Tagging Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out for Loop": {
      "main": [
        [
          {
            "node": "Tagging Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Blog Tags Generator": {
      "main": [
        [
          {
            "node": "Split Out for Loop",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch All Tags",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Return Tag ID & Name": {
      "main": [
        [
          {
            "node": "Tagging Loop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch One WordPress Blog": {
      "main": [
        [
          {
            "node": "Blog Tags Generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Blog Tags Generator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Merge Old and Mapped Tags": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}