How to programmatically connect content

If you want to connect content programmatically across sites you need to know the IDs of the posts you want to connect beforehand. So let say that we have 3 sites with site ids 1, 2 and 3 and we want to connect a post with the following post ids on each site:

post id 42 in site 1
post id 123 in site 2
post id 321 in site 3

Following code snippet creates the $contentIds array of key value pairs with site id as key and post id as value. Afterwards we pass it to the createRelationship method as first parameter to connect the content.

$api = \Inpsyde\MultilingualPress\resolve(

$contentIds = [
1 => 42,
2 => 123,
3 => 321,

$api->createRelationship($contentIds, 'post');

Build the perfect multilingual webshop with WooCommerce and our plugins MultilingualPress and CentralStock!