Created
February 7, 2019 17:20
-
-
Save paulotruta/701fa7641616c34a023c5f39d5a88638 to your computer and use it in GitHub Desktop.
Get WPML translated post ids from original post ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_translated_post_ids($post_id) { | |
global $sitepress; | |
$translated_ids = Array(); | |
if(!isset($sitepress)) return; | |
$trid = $sitepress->get_element_trid($post_id, 'post_product'); | |
$translations = $sitepress->get_element_translations($trid, 'product'); | |
foreach( $translations as $lang=>$translation){ | |
$translated_ids[] = $translation->element_id; | |
} | |
return $translated_ids; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, thanks! Works perfectly