Support » Plugin: Polylang » [Plugin: Polylang] creating page via wp_insert_page, update meta data

  • Hello… great plugin thanks 🙂

    I’ve been looking round forumn, code… I create some posts in php using the wp_insert_page() and realized I need to create the langauge meta data, could you point me to the rough places to find examples of this ?

    I’m not quite sure how this is work.. seperate posts are created for each langauge… but I think I just need to put the right meta data in ?

    Thanks
    Neil

    http://wordpress.org/extend/plugins/polylang/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chouby

    (@chouby)

    The language is a custom taxonomy. You can look in the function save_post in admin_filters.php. Basically I set posts and pages language with:

    wp_set_post_terms($post_id, $lang, 'language' );

    where $lang is the term slug of the language (the 2-characters code)

    Thanks that was quick… although I’d just found the function you mention and the following seems to work… 🙂 in case anyone else needs it or can improve upon this 🙂

    wp_set_post_terms($postID, ‘en’, ‘language’ );
    update_metadata(‘homestead’, $postID, ‘_translations’, ‘en’);

    Great little plugin by the way, thanks… I’m learning a little but still more to go 🙂
    Neil

    Plugin Author Chouby

    (@chouby)

    It’s curious that your update_metadata line works.

    I currently do not provide a convenient API to set language and translations. I may improve this in the future. Currently, the best way to save post or page languages and translations would be something like this:

    wp_set_post_terms($en_post_id, 'en', 'language' );
    wp_set_post_terms($fr_post_id, 'fr', 'language' );
    wp_set_post_terms($de_post_id, 'de', 'language' );
    $translations = array('fr'=> $fr_post_id, 'de'=> $de_post_id);
    global $polylang;
    if (isset($polylang))
      $polylang->save_translations('post', $en_post_id, $translations)

    You don’t need to call save_translations a second time for $fr_post_id or $de_post_id. Always use ‘post’, even for pages.

    Thanks I’ll try that also… I’m guessing it is working (I’ll check again :)) as I currently only have these posts in one langauge. But I like to learn the better way to do things…

    I was wondering how to get access to functions in other plugins etc

    Neil

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Polylang] creating page via wp_insert_page, update meta data’ is closed to new replies.