[resolved] From a bilingual custom post type to two translated posts (3 posts)

  1. Fourmi
    Posted 2 years ago #

    We recently moved a database of 1300-ish entries to WordPress.

    We created a custom post type for these, and added custom fields such as French Description - English Description in the same post.

    The rest of the site is translated with Polylang and is working fine (like all of our websites using this plugin). But we have issues with those custom posts and we want to get them into Polylang.

    I'm trying to find out how to do it. Here's my steps for now:

    - Making sure the language of all posts is set in wp_term_relationships
    - Duplicate posts from wp_posts (making sure to adapt guid and slug)
    - Duplicate all of the original post data from wp_postmeta and change the post id to the new id
    - Set the language of the new post in wp_term_relationships
    - Add to wp_term_taxonomy: post_translations: a:2:{s:2:"fr";i:ORIGINAL ID;s:2:"en";i:NEW ID;}

    And then I need to link the two posts together, I guess in wp_terms, using term_id from my newly created entry in wp_term_taxonomy. But I have no idea how to get name and slug values, which I see should start with pll_

    Can you help me with this one? And do you think my first steps will work?

    Thanks in advance!


  2. Chouby
    Plugin Author

    Posted 2 years ago #


    There are Polylang functions to do this:

    global $polylang;
    $polylang->model->set_post_language($en_post_id, 'en');
    $polylang->model->set_post_language($fr_post_id, 'fr');
    $polylang->model->save_translations('post', $en_post_id, array('fr' => $fr_post_id));

    In Polylang 1.5, the task will be simplified with new API functions:

    pll_set_post_language($en_post_id, 'en');
    pll_set_post_language($fr_post_id, 'fr');
    pll_save_post_translations(array('en' => $en_post_id, 'fr' => $fr_post_id));
  3. Fourmi
    Posted 2 years ago #

    Great! Thank you so much, it works!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Polylang
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic