---
title: "Push WordPress Content from CI/CD with WP-CLI"
url: "https://wpimportexport.com/push-wordpress-content-ci-cd-wp-cli/"
description: "Push posts from staging to production in your CI/CD pipeline: a release file, one WP-CLI script and an exit code that stops the pipeline on failure."
type: post
published: 2026-11-23T15:00:00+00:00
modified: 2026-11-11T10:01:10+00:00
categories: ["Content Sync", "Tutorials"]
tags: ["Content Sync", "WooCommerce"]
docs_topics: ["Sync and migration"]
---

# Push WordPress Content from CI/CD with WP-CLI

Your code goes from staging to production through a pipeline: commit, build, deploy. Content usually doesn’t. Someone still has to open the staging site and push the new posts by hand after each release. With **Import Export by RockStarLab** and WP-CLI, the pipeline can push the content too: a list of slugs in the repository, one script, and an exit code that stops the pipeline if the push fails.

**Free:** Content Sync and the `wp rsl-ie` commands are in the free plugin. Use version 2.1.59 or newer on staging and production.

## How it works

- The release lists the slugs of the posts to publish in a file, `content-release.txt`.
- A script on the staging server finds those posts and matches them with production by title.
- It starts a Content Sync push with `wp rsl-ie ability sync-push-start` and waits for it with `wp rsl-ie job wait`.
- The exit code is 0 when the push is done and 1 when it fails, so the pipeline knows the result.

A push replaces the matched posts on production. [Back up production](https://wpimportexport.com/how-to-create-a-wordpress-website-backup-and-restore-it/) before the first run, or ask your AI agent to start the backup.

## Before you start

- Connect staging to production in **Import Export → Content Sync** (see [how Content Sync works](https://wpimportexport.com/how-content-sync-works-api-keys-push-pull/)). Note the ID of the production site: `wp rsl-ie ability connection-list --user=admin` shows it. In our test it is 2.
- WP-CLI must run on the staging server as an administrator (`--user=admin`). `jq` is used to read the JSON results.

## The release file

On staging, we changed the opening date in the post “Our New Roastery Opens in March” and wrote a new post, “Holiday Opening Hours”. The release file lists both slugs, one per line:

```
our-new-roastery-opens-in-march
holiday-opening-hours
```

## The script

Save it as `push-content.sh` next to the release file and make it executable (`chmod +x push-content.sh`). Set `SITE_ID` to the production site ID:

```
#!/usr/bin/env bash
# Push the posts listed in content-release.txt from staging to production.
set -euo pipefail

WP="${WP:-wp} --user=admin"
SITE_ID=2   # the production site in Import Export -> Content Sync
RUN_ID="${CI_RUN_ID:-$(date +%Y%m%d%H%M%S)}"   # one push per pipeline run

# 1. Slugs from the release file -> post IDs on staging
IDS=$(grep -v '^\s*$' content-release.txt | while read -r slug; do
  $WP post list --post_type=post --name="$slug" --field=ID
done | paste -sd, -)
if [ -z "$IDS" ]; then echo "No posts found for content-release.txt"; exit 1; fi
echo "Posts to push: $IDS"

# 2. Match them with production by title (null = create a new post)
AUTOMAP=$($WP rsl-ie ability sync-auto-map \
  "{\"site_id\":$SITE_ID,\"post_type\":\"post\",\"post_ids\":[$IDS]}")
if [ "$(echo "$AUTOMAP" | jq '.ambiguous | length')" != "0" ]; then
  echo "Several production posts have the same title:"; echo "$AUTOMAP" | jq .ambiguous
  exit 1
fi
MAPPING=$(echo "$AUTOMAP" | jq -c .mapping)
echo "Mapping: $MAPPING"

# 3. Start the push and wait for it
JOB=$($WP rsl-ie ability sync-push-start \
  "{\"site_id\":$SITE_ID,\"post_type\":\"post\",\"post_ids\":[$IDS],\"post_mapping\":$MAPPING,\"request_id\":\"content-$RUN_ID\"}" \
  | jq -r .job_id)
echo "Job: $JOB"
$WP rsl-ie job wait "$JOB"
```

What each step does:

1. **Slugs to IDs.** `wp post list --name` finds each post on staging.
2. **Matching.** `sync-auto-map` looks for posts with the same title on production. A post that is not there yet gets `null` and is created. If two production posts have the same title, the script stops, so nothing is overwritten by mistake.
3. **Push.** `sync-push-start` queues the push. The `request_id` comes from the pipeline run, so a repeated step of the same run does not push twice.
4. **Wait.** `wp rsl-ie job wait` runs the push in the same process, without waiting for WP-Cron, prints the result and sets the exit code.

## Run it

In the pipeline, run the script on the staging server after the code deploy, with the run number of your CI tool in `CI_RUN_ID`. Our run:

![Terminal: push-content.sh finds 2 posts, maps one to production and one as new, job 5469 completed with 2 succeeded and exit code 0](https://wpimportexport.com/wp-content/uploads/2026/11/01-ci-push.webp)

_The script pushed 2 posts and exited with 0._

The push took about 20 seconds. Production now has the new post, and the updated one moved to the top of the list sorted by last change:

![Posts screen on production with Holiday Opening Hours and Our New Roastery Opens in March at the top](https://wpimportexport.com/wp-content/uploads/2026/11/02-production-posts.webp)

_Production after the push: one new post and one updated post._

We ran the script again with the next run number. This time `sync-auto-map` found both posts on production, so the job updated 2 posts and created none.

## Limits

- One script run pushes one post type, `post` or `page`. Run it twice for both.
- One push takes up to 50 posts.
- Posts are matched by exact title. Rename a post on both sites before the push, or pass the production ID in the mapping yourself.

## With an AI agent

An AI agent connected to staging through the WordPress MCP Adapter (see [connecting Claude Code to WordPress](https://wpimportexport.com/connect-claude-code-to-wordpress-mcp/)) can tell you what the last release pushed:

```
What did the last content push from CI send to production?
```

In our run, the agent called `rsl-ie/job-list` to find the job, then `rsl-ie/sync-job-status`. The status shows that the push updated 2 posts, “Our New Roastery Opens in March” and “Holiday Opening Hours”, and synced 1 image.

## FAQ

### Does the pipeline need WP-Cron?

No. `wp rsl-ie job wait` runs the push in the WP-CLI process until it finishes.

### What happens if the push fails?

The command prints the error and exits with 1, so the pipeline step fails.

### Are the images in the posts copied?

Yes. A push copies the images of the posts, the same as a push from the Posts screen.

### Can I push pages?

Yes. In the script, replace `post` with `page` in the `--post_type` option and in both `post_type` values, and list page slugs in the release file.

## Related Guides

- [WP-CLI Import and Export for WordPress: CSV, Excel and Cron Scripts](https://wpimportexport.com/wp-cli-import-export-wordpress/)
- [Dev, Staging, Production: A Content Workflow for Three WordPress Sites](https://wpimportexport.com/dev-staging-production-wordpress-content-workflow/)
- [Auto-Match by Title: Match Posts Between WordPress Sites](https://wpimportexport.com/auto-match-by-title-map-posts-between-sites/)

Get the free plugin on [WordPress.org](https://wordpress.org/plugins/import-export-by-rockstarlab/).
