You will need to get the current language, get the translated post id with the source post id and current language, and then get the post from wordpress using the translated post id. This will work for the source and all translations.
Below is the Polylang function documentation page:
https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/
Here are some screenshots of the home page after implementing this along with a screenshot of the 'home_news_one' shortcode implementation.
Here is the code snippet used in the screenshot above. They should be able to adapt it for all their custom post types and shortcodes. It's pretty simple.
/* This block of code gets the current language of the page from polylang
and then uses the language slug and source post id to get the translated_post_id.
Then use the translated_post_id with the WordPress get_post function. */
if (function_exists('pll_current_language') && function_exists('pll_get_post')) {
$lang = pll_current_language();
$translated_post_id = pll_get_post($customFieldDataForNewsOne[0], $lang);
$newsOnePost = get_post($translated_post_id);
}
Comments
0 comments
Article is closed for comments.