• Resolved ashpriom

    (@ashpriom)


    Hi,

    I used the following to get the ID of the linked post:

    if(function_exists('pll_get_post')){ echo pll_get_post($postID,$currentLang); }

    Concrete scenario: The $postID is ’46’ (French version of the post) and $currentLang is ‘fr’. So it should return the $postID of the English version of this French post right? Which is 11026. But I am getting $postID of the same page, 46.

    My objective is to get some custom field values from the English post so that users don’t need put the same information twice. This is why I need the linked post ID to fetch data. May be I’m missing something obvious. Can you help please?

    https://www.ads-software.com/plugins/polylang/

Viewing 1 replies (of 1 total)
  • Thread Starter ashpriom

    (@ashpriom)

    Alright, I figured it out. Some obvious that confused me.

    Say for instance, if you are on a French post, but you want to grab the ID of its English counterpart, do this:

    $postID = get_the_ID();
    if (function_exists('pll_current_language')) {
    $currentLang = pll_current_language('slug');
    }
    $translationID = pll_get_post($postID,'en');

    First detect the current post ID and its language. Okay.
    Then apply the pll_get_post($postID, "language code"). The “en” here is the language code for the target post ID. For instance if you want German counterpart’s ID, it would be ‘de’, and vice versa.

Viewing 1 replies (of 1 total)
  • The topic ‘pll_get_post() function is not working’ is closed to new replies.