Assign a Category to Crossposted Posts

I was thinking for a long time about adding the settings for it to my plugins, but turns out that there could be a lot of customisations and it would be much better to accomplish it with a filter hook (code snippet). Please check the examples below and also the explanation how to use them.

In case you’re using a multisite version of the plugin:

add_filter( 'rudr_crosspost_taxonomy_destination', function( $terms, $blog_id ) {

	if( 3 === $blog_id ) { // target blog ID

		$terms = array(
			// 'taxonomy name' => array( 'slug1', 'slug2', ... ),
			// in case you do not want any category to be assigned on Site 2
			'category' => array(),
			// custom taxonomy term slugs on Site 2
			'city' => array( 'athens', 'istanbul', 'dubai', 'colombo' ),
		);

	}
	return $terms;

}, 10, 2 );

For a non-multisite version of the plugin:

add_filter( 'rudr_swc_taxonomy_destination', function( $terms, $blog_url ){

	if( 'https://rudrastyh.com' === $blog_url ) { // target blog URL

		$terms = array(
			// 'taxonomy rest base' => array( 'ID1', 'ID2', ... ),
			// in case you do not want any category to be assigned on Site 2
			'categories' => array(),
			// term IDs on Site 2 (but for wordpress.com sites – also slugs)
			'cities' => array( 5, 15, 125, 127 ),
		);

	}
	return $terms;

}, 10, 2 );

If you don’t know where to use this piece of code, check this guide.

Need more help?