WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
Is there a function to get translations by id or slug (2 posts)

  1. nabil_kadimi
    Member
    Posted 1 year ago #

    Hello,

    I have the post slug and I want to get the translation (post object) for a language, is there a function that does this?

    Something like:

    $english_slug = 'ny_jobs';
    $french_translation = get_translation($english_slug, 'fr');

    PS.
    Nice plugin Chouby

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

  2. maxoud
    Member
    Posted 1 year ago #

    There is no straight way, by you can do following:

    //Find the post id by it's slug
    $id = $wpdb->get_var("SELECT ID FROM $wpdb->post WHERE post_name = 'ny_jobs'");
    //Get post translation id
    $tr_id = pll_get_post($id,'fr')
    //Get the translation post object
    $post_object = get_post($tr_id)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic