Crossposting from Staging to Production

You can also use my crossposting plugin in cases when you edit your content on a staging website and once ready, to push it on a live website, per post basis.

But in cases like this a little bit of extra configuration is required.

First, you will probably need to crosspost all the images in the post content. In order to do so, just go to Settings > Crosspost > Fields and activate this option:

crosspost content images plugin feature
Please keep in mind that this is an experimental feature, so if you have issues with it, you can just upload your images manually and then process to the next step in this guide.

Second, you need to replace URLs in the post content, it is easy, just use the code snippet below on your staging site (the site you’re crossposting from).

add_filter( 'rudr_swc_pre_crosspost_post_data', function( $post_data, $blog ) {
	// just replacing the current (stanging) site URLs with the production site URLs
	$post_data[ 'content' ] = str_replace( site_url(), $blog[ 'url' ], $post_data[ 'content' ] );
	return $post_data;
}, 10, 2 );

Please note, that both URLs we’re replacing are without / slashes.

If you’re using WooCommerce, you need to use rudr_swc_pre_crosspost_product_data instead of rudr_swc_pre_crosspost_post_data for products.

add_filter( 'rudr_swc_pre_crosspost_product_data', function( $product_data, $blog_id ) {
	$blog = Rudr_Simple_WP_Crosspost::get_blog( $blog_id );
	$product_data[ 'description' ] = str_replace( site_url(), $blog[ 'url' ], $product_data[ 'description' ] );
	return $product_data;
}, 10, 2 );

In case you have some URLs in your post meta (may be useful for Elementor and stuff).

add_filter( 'rudr_swc_pre_crosspost_meta', function( $value, $key, $id, $blog ) {
	// you can also check for specfic meta keys here and I recommend to do that
	// if( 'some_meta_key' !== $key ) {
	// 	return $value;
	// }
	$value = str_replace( site_url(), $blog[ 'url' ], $value );
	return $value;
}, 10, 4 );

Once again, if you don’t know where to use these code snippets.

Need more help?