Дата публикации : 2022.04.23
Автор:Виноградов Александр
Рейтинг статьи:
Making a bunch of translated posts in the Polylang Wordpress plugin
And since the pll_save_post_translations function itself works, I still haven’t figured it out, however, the problem can be solved through a lower-level function of the same plugin PLL()->model->post->save_translations( $post_ru, array(en=>$post_en) );
This function is necessary to link language versions of a post, for example, if you need to transfer translated articles to a server on which the post IDs have already been broken, that is, posts have been added.
<?php
//Post with Russian language id, substitute yours
$post_ru = 13889;
//Post id in English or any other language
$post_en = 19623;
/*We clearly establish that the post belongs to one language or anotherу*/
pll_set_post_language($post_ru, 'ru_RU');
pll_set_post_language($post_en, 'en_US');
//we link the translations together so that they are displayed together in the admin panel and on the front
PLL()->model->post->save_translations( $post_ru, array('en'=>$post_en) );
PLL()->model->post->save_translations( $post_en, array('ru'=>$post_ru) );