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
| Flag | Description |
|---|---|
--post_title=TITLE | Post title |
--post_content=CONTENT | Post body (HTML or plain text) |
--post_excerpt=EXCERPT | Short excerpt |
--post_status=STATUS | publish, draft, private, pending |
--post_type=TYPE | post, page, or custom type slug |
--post_author=ID | Author user ID |
--post_date=DATE | Publish date: YYYY-MM-DD HH:MM:SS |
--post_name=SLUG | URL slug |
--post_parent=ID | Parent post ID (for pages) |
--page-template=TEMPLATE | Page template filename |
--tags_input=TAGS | Comma-separated tags |
--post_category=IDS | Comma-separated category IDs |
--porcelain | Output only the new post ID |
--FIELD=VALUE | Any 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
- Always use
--post_status=draftwhen creating content programmatically until reviewed. - Use
--porcelainto capture the ID for follow-up commands (adding meta, terms). - 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
wp post update— update after creation.wp post meta— add meta fields to the new post.wp post term— assign taxonomy terms.