Last active
March 6, 2019 08:16
-
-
Save jartes/3b48168e221edce3a1be to your computer and use it in GitHub Desktop.
WordPress WPML has_category()
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 has_wpml_category( $category_slug = null ) { | |
// bye bye no slug provided | |
if ( is_null( $category_slug ) ) | |
return false; | |
// Default languange don't need to be checked | |
global $sitepress; | |
if ( ICL_LANGUAGE_CODE == $sitepress->get_default_language() ) | |
return has_category( $category_slug ); | |
// Multilingual category | |
$cat_object = get_category_by_slug( $category_slug ); | |
$cat_id = $cat_object->term_id; | |
return has_category( icl_object_id( $cat_id, 'category', true ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment