Skip to content

Instantly share code, notes, and snippets.

@paulotruta
Created February 7, 2019 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulotruta/701fa7641616c34a023c5f39d5a88638 to your computer and use it in GitHub Desktop.
Save paulotruta/701fa7641616c34a023c5f39d5a88638 to your computer and use it in GitHub Desktop.
Get WPML translated post ids from original post ID
<?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;
}
@LuukVanDongen
Copy link

Wow, thanks! Works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment