wp_create_post
Create a new WordPress post from scratch on a configured site. Supply content as raw markup or block array; returns the new post ID. Works on local or production with confirmation.
Instructions
Create a NEW post from scratch on a configured site, with the body carried content-safe (base64 in code) — so you never have to hand-quote multi-line block markup into a wp post create command or write a throwaway PHP file into the container just to author a post. Returns the new post's ID (new_id), which you then build up compositionally with wp_block (insert / update-attrs). Supply the body EITHER as content (a raw post_content markup string) OR as blocks (an array of block specs — raw markup strings and/or {name, data} objects — serialized server-side with serialize_blocks() so self-closing ACF blocks and inner blocks stay byte-faithful); omit both for an empty post. fields sets any additional post columns (post_excerpt, post_author, post_parent, menu_order, post_name, ...). The new post is re-read and its content md5 is compared to the intended body (verified). Content never passes through the caller's text. Creating on target='production' requires confirm=true when PROD_GUARD is enabled. To COPY an existing post across environments use wp_clone_post instead; this tool authors a brand-new post from given values.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| env | No | Terminus environment override (e.g. 'dev', 'test', 'live') for target='production' on a Terminus site. Omit for the site's TERMINUS_ENV. | |
| site | No | Which configured site to target (matches a [site:NAME] section in wp-cli.conf). Omit for DEFAULT_SITE or the sole site. | |
| title | No | The post title (post_title). Optional. | |
| blocks | No | Array of block specs to serialize as the initial body: each item is raw block markup (string) OR an object {"name": "acf/...", "data": {field: value}}. Serialized server-side via serialize_blocks(). Mutually exclusive with 'content'. | |
| fields | No | Optional additional post fields to set (e.g. {"post_excerpt":"...","post_author":2,"post_parent":10,"menu_order":3,"post_name":"slug"}). | |
| status | No | Post status (e.g. 'draft', 'publish', 'private'). Default 'draft'. | draft |
| target | No | Where to create the post. 'local' = Docker container (default). 'production' = remote environment; transport (Terminus vs SSH) is chosen by the site's conf. | local |
| confirm | No | Required to create on a production site when the guard is enabled. Default: false. | |
| content | No | Raw post_content markup (a full block document). Mutually exclusive with 'blocks'. Omit both for an empty post. | |
| post_type | No | Post type to create (e.g. 'post', 'page', a CPT slug). Default 'post'. | post |