WP-CLI Commands

Currently, you can run WP CLI commands for both multisite and non-multisite versions of the plugin.

Below, you can find the documentation for all of them.

Standalone Sites

Since version 3.8, my plugin Simple WordPress Crossposting comes with WP-CLI commands.

wp swc connect

This command allows you to connect posts that already existed before you installed my plugin. Posts with the same slugs are going to be connected.

ArgumentDescription
[--id=<post-ID>]You can provide a specific post ID here. If not provided, the plugin will try to connect all published posts (of allowed post types).
[--site=<site-URL>]You can provide a site URL for which you would like to run this command, by default – the first added website in the plugin settings.

Connect a post with ID=1328 to the website rudrastyh.com:

wp swc connect --id=1328 --site=rudrastyh.com
connect an existing post with the same slug with WP-CLI

Connect all posts to the first added site in the plugin settings:

wp swc connect
WP-CLI bulk connect posts

wp swc crosspost

ArgumentDescription
<post-ID>Provide a specific post ID here.
[--site=<site-URL>]You can provide a site URL you would like to run this command for. By default – the first added website in the plugin settings.

Crosspost (publish or update) a post with ID=5:

wp swc crosspost 5
Example of crossposting a post with WP-CLI command

This command currently doesn’t support the progress bar like wp swc connect, but you can try to combine it together with wp post list. For example, this way we can crosspost all the pages:

for id in $(wp post list --post_type="page" --fields=ID )
do
	wp swc crosspost $id
done

Or for example, you can crosspost WooCommerce products starting with the old ones:

for id in $(wp post list --post_type="product" --orderby="date" --order="ASC" --fields=ID )
do
	wp swc crosspost $id
done

I didn’t have a chance to test it for a large amount of posts, so please be careful.

WordPress Multisite

If you’re using a multisite version of the plugin – Simple Multisite Crossposting, it also allows you to enjoy WP CLI commands. They are available in plugin version 5.0 and above.

But when working with WordPress Multisite network in CLI, you need to remember that by default the commands are running from the main site of the network. But you can run them from any sub-site of the network you want, just by providing --url=<url> global parameter.

For example:

wp --url=site2.rudrastyh.com smc connect --id=123

Now, let’s take a look at the commands themselves.

wp smc connect

ArgumentDescription
[--id=<post-ID>]Provide a specific post ID here. By default, the plugin will try to connect all published posts (of allowed post types).
[--blog_id=<blog-ID>]The target subsite ID in the multisite network.

This command allows you to link (connect) the posts with the same slugs that existed on your subsites before you installed the plugin.

wp smc crosspost

ArgumentDescription
<post-ID>The post ID.
[--blog_id=<blog-ID>]The target subsite ID we would like to crosspost to.

Publish (or update) a post with ID=1 to a subsite with ID=8:

wp smc crosspost 1 --blog_id=8
crosspost a post within a multisite network with WP CLI

In order to run the bulk crossposting (for multiple posts at once), I’d recommend you use this command together with wp post list.

for id in $(wp post list --post_type="page" --fields=ID )
do
	wp smc crosspost $id --blog_id=8
done

Need more help?