WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
creating page via wp_insert_page, update meta data (5 posts)

  1. dudman
    Member
    Posted 2 years ago #

    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/

  2. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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)

  3. dudman
    Member
    Posted 2 years ago #

    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

  4. Chouby
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  5. dudman
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags