// NODE.JS · WORDPRESS · AUTOMATION

WordPress Auto-Poster: Automating Content Creation with Node.js

View on GitHub

One recurring challenge in content-heavy WordPress sites is the overhead of populating them with structured, realistic content — whether for staging environments, demos, or testing editorial workflows. I built content-creator to solve this with a single Node.js script that handles the entire pipeline: from generating text and fetching images to publishing posts or pages directly via the WordPress REST API.

What it does

The tool runs in batch mode from the command line. You tell it how many items to create, what status to assign them, and whether you want posts or pages. It takes care of everything else — including making sure the target category exists before writing a single post.

01
Resolve category — checks whether the auto-posted-content category exists in WordPress; creates it automatically if not. Runs once per batch.
02
Fetch content — pulls markdown from the Brett Terpstra Lipsum API. The first heading becomes the post title; the rest is the body.
03
Convert to HTML — markdown is parsed with marked (GFM enabled) before being sent to WordPress.
04
Fetch image — pulls a random 600×400 image from Picsum Photos.
05
Upload image — sends the image to the WordPress Media Library, receives a media ID in return.
06
Create post or page — publishes the item with the generated title, HTML body, featured image, category, and any extra parameters. Steps 2–6 repeat for each item in the batch.

CLI interface

The script is designed to be run directly from the terminal with sensible defaults — one draft post if you call it with no arguments — and a full set of flags for when you need more control:

# Default: 1 draft post
node index.js

# 5 draft posts
node index.js --count 5

# 3 published posts
node index.js --count 3 --status publish

# 2 draft pages with a page template
node index.js -y pages -c 2 -t full-width.php

# Show all options
node index.js --help

The --status flag accepts any WordPress post status: draft, publish, pending, private, or future. The --template flag is only included in the API request when explicitly supplied — it's omitted entirely otherwise, rather than sending an empty value.

WordPress REST API surface

The tool touches five WordPress endpoints. All requests use HTTP Basic Auth with an Application Password — the safer option compared to a login password since it can be revoked independently from WordPress admin:

Action Method Endpoint
Look up categoryGET/wp-json/wp/v2/categories?slug=…
Create categoryPOST/wp-json/wp/v2/categories
Upload imagePOST/wp-json/wp/v2/media
Create postPOST/wp-json/wp/v2/posts
Create pagePOST/wp-json/wp/v2/pages

Project structure

The code is split into three focused modules, each with a single responsibility:

content-creator/
├── index.js            # CLI parsing, orchestrates the full flow
├── contentService.js   # Fetches markdown content, image, converts to HTML
├── wordpressService.js # WordPress REST API calls
├── .env.example        # Environment variable template
└── package.json

Configuration is handled through a .env file with three variables: the WordPress base URL, a username, and an Application Password. Copy .env.example, fill in your credentials, and the tool is ready to run.

Why I built it this way

A tool that solves one problem cleanly is worth more than a framework that solves ten problems awkwardly.

The scope is intentionally narrow. This isn't a CMS replacement or a full content pipeline — it's a focused utility for a specific task: populating a WordPress instance with structured content quickly and repeatably. The three-module structure keeps concerns separated without over-engineering something that's meant to be transparent and easy to modify.

If you work with WordPress and find yourself manually populating test environments or staging sites, content-creator is worth a look. The setup takes about two minutes.

← All Articles