Skip to content

Instantly share code, notes, and snippets.

@alexmccabe
Created October 11, 2018 15: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 alexmccabe/d911fe5303ecd95e1287f7a291d7cea1 to your computer and use it in GitHub Desktop.
Save alexmccabe/d911fe5303ecd95e1287f7a291d7cea1 to your computer and use it in GitHub Desktop.
WPML will return all languages for the current page, even if they are in draft mode. This is not right. This horrible work around solves that issue.
function wpml_get_languages ($options = 'skip_missing=1&orderby=code&order=desc') {
$languages = icl_get_languages($options);
$currentID = get_queried_object_id();
foreach ($languages as $key => $language) {
$id = icl_object_id($currentID, 'page', false, $language['language_code']);
$status = get_post_status($id);
if ($status !== 'publish') {
unset($languages[$key]);
}
}
return array_values($languages);
}
@hardweb-it
Copy link

After 4 years this workaround still working fine! Tested today 17/11/2022 and it saved my day (that's also my bday :D )
Thank you @alexmccabe! Love you!

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