Skip to main content

wp post create

Overview

Programmatically create any post type — post, page, or custom — with full control over title, content, status, author, taxonomy, and meta. Essential for seeding content, scripted publishing, and migrations.

What It Does

wp post create calls wp_insert_post() with the provided arguments and outputs the new post ID. Content can be provided inline or read from a file.

Syntax

wp post create [--<field>=<value>] [OPTIONS]

Common Options

FlagDescription
--post_title=TITLEPost title
--post_content=CONTENTPost body (HTML or plain text)
--post_excerpt=EXCERPTShort excerpt
--post_status=STATUSpublish, draft, private, pending
--post_type=TYPEpost, page, or custom type slug
--post_author=IDAuthor user ID
--post_date=DATEPublish date: YYYY-MM-DD HH:MM:SS
--post_name=SLUGURL slug
--post_parent=IDParent post ID (for pages)
--page-template=TEMPLATEPage template filename
--tags_input=TAGSComma-separated tags
--post_category=IDSComma-separated category IDs
--porcelainOutput only the new post ID
--FIELD=VALUEAny WP_Query accepted field

Basic Usage

Create a published post

wp post create \
--post_title="Hello World" \
--post_content="This is the content." \
--post_status=publish

Create a draft page

wp post create \
--post_type=page \
--post_title="About Us" \
--post_status=draft

Create from a file (for long content)

wp post create /path/to/content.html \
--post_title="Long Article" \
--post_status=publish \
--post_type=post

Get only the new post ID

POST_ID=$(wp post create --post_title="New Post" --post_status=draft --porcelain)
echo "Created post ID: $POST_ID"

Real-World Scenarios

Scenario 1: Seed a blog with placeholder posts

for i in $(seq 1 10); do
wp post create \
--post_title="Sample Post $i" \
--post_content="Content for post $i." \
--post_status=publish \
--post_date="2025-0${i}-01 10:00:00"
done

Scenario 2: Create a page and assign a template

wp post create \
--post_type=page \
--post_title="Contact Us" \
--post_status=publish \
--page-template="templates/contact.php"

Scenario 3: Migrate articles from a CSV

while IFS=',' read -r title content author_id; do
wp post create \
--post_title="$title" \
--post_content="$content" \
--post_author="$author_id" \
--post_status=publish
done < articles.csv

Best Practices

  1. Always use --post_status=draft when creating content programmatically until reviewed.
  2. Use --porcelain to capture the ID for follow-up commands (adding meta, terms).
  3. Read content from a file for long posts to avoid shell escaping issues.

Quick Reference

wp post create --post_title="Title" --post_status=publish
wp post create --post_type=page --post_title="Page" --post_status=draft
wp post create content.html --post_title="Article" --post_status=publish
POST_ID=$(wp post create --post_title="X" --porcelain)

Next Steps