Created
October 11, 2018 15:20
-
-
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.
This file contains hidden or 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
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!