Wordpress - Manually link two post translation with polylang
Asked Answered
S

2

6

I am currently developing a plugin for multiposting on multisite wordpress.

I wanted the plugin to work with Polylang, it works well when it comes to setting the right language, but i can't find a way to connect to its other translations ( when i post from a blog to the others, otherwise on the same site, it works ).

I've searched in their documentation, and through their plugin, but did not found something that could actually help me.

Do you have any idea how I can set manually the link between translations of the same post ?

Thank's by advance ! :)

Samford answered 7/10, 2016 at 10:38 Comment(0)
S
2

I found a solution to this.

You just have to create a wp_insert_term like this, with a different description:

wp_insert_term($group = uniqid('pll_'), 'post_translations', array('description' => serialize(['fr' => 453, 'en' => 455])));

And then you set this term to your concerned posts or custom post :

wp_set_object_terms( $postId, yourTerm, 'post_translations');

And here you are, your post are linked properly in you back end !

Samford answered 7/10, 2016 at 15:10 Comment(0)
R
2

This is the purpose of pll_save_post_translations (for translations post relations) and pll_save_term_translations (for translation terms relation) both defined in /wp-content/plugins/polylang/include/api.php.

Both of these functions will wait for an associative array with :

  • Key : ISO langage code on 2 letters (i.e. 'en')
  • Value : post id or term id
Raasch answered 28/2, 2017 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.