• Resolved Matt Gibson

    (@gothickgothickorguk)


    Hi!

    In a theme I’m developing, I’m programatically adding a (custom post type) post for each user, to act as a “profile” page in a membership directory. For a single language, this is working fine:

    $post = array (
    					'post_author' => $user_id,
    					'post_type' => 'jnet_member'
    			);
    			$result = wp_insert_post ( $post, true );

    Now I’m moving to polylang, I’d like to add two posts instead, one in English and one in Japanese, so that the membership directory can also be bilingual, using polylang’s helpful support for translation of custom post types.

    What’s the best way of programatically adding a post in one language, and its translation in another language?

    (I had a look through previous questions, but I wasn’t sure if things had moved on, as they’re all quite old, and I know polylang is being developed very rapidly…)

    Thanks,

    Matt

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

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

    (@chouby)

    That should work:

    global $polylang;
    
    $post = array (
    	'post_author' => $user_id,
    	'post_type' => 'jnet_member'
    );
    $result_en = wp_insert_post ( $post, true );
    $result_ja = wp_insert_post ( $post, true );
    
    $polylang->model->set_post_language($result_en, 'en');
    $polylang->model->set_post_language($result_ja, 'ja');
    $polylang->model->save_translations('post', $result_ja, array('en' => $result_en));

    Thread Starter Matt Gibson

    (@gothickgothickorguk)

    Hi Chouby,

    Fabulous, that’s working perfectly.

    Thanks,

    Matt

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Best way to pragmatically add a post in a language?’ is closed to new replies.