Back to blog
5 min read Content Sync

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 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). 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
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
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) 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.

Get the free plugin on WordPress.org.

Dmitriy
About author

Dmitriy

WordPress Developer with 15+ years of commercial experience. Elite Author on ThemeForest and creator of custom WordPress plugins. Passionate about clean code, performance optimization, and building useful tools for the WordPress community.

JOIN THE CONVERSATION

Comments 0

Have a question or a tip to share? Leave it below.

Leave a comment

Your email address will not be published. Required fields are marked *

We store your name, email and comment to show and moderate it; your email is never published. Spam protection is provided by Cloudflare Turnstile and profile pictures by Gravatar. See our Privacy Policy.


Try the plugin with no risks!

New users get 1 month with access to all premium features. Experience the most powerful WordPress data engine today.

Download Now
Get PRO for FREE