Copy and synchronize WordPress posts programmatically with Polylang

You can batch sync your posts with the following script. If you have a lot of posts to sync, this script should be run outside of WordPress.