pll_fs_base_is_term polylang support functions

29 May 2020
0 Comments
                
                    
function pll_fs_base_is_term($term, $taxonomy = 'category')
{
//    global $wp_query;
    if (is_int($term)) {
        if (0 === $term) {
            return 0;
        }
    }
    $term_id = $term;
    if (function_exists('pll_the_languages')) {
        $pll_current_language = pll_current_language();
        $term_arr = pll_get_term_translations($term);
        if (isset($term_arr[$pll_current_language])) $term_id = $term_arr[$pll_current_language];
    }
    if (is_category($term_id)) {
        return true;
    }
    if (is_tax($taxonomy, $term_id)) {
        return true;
    }
    return false;
}
                
            

EG: if (pll_fs_base_is_term(86)) get_template_part( 'template-parts/posts/archive', 'du-an' );

                
                    
function pll_fs_base_is_term_with_child($term, $taxonomy = 'category')
{

    if (is_int($term)) {
        if (0 === $term) {
            return 0;
        }
    }

    $term_id = $term;
    if (function_exists('pll_the_languages')) {
        $pll_current_language = pll_current_language();
        $term_arr = pll_get_term_translations($term);
        if (isset($term_arr[$pll_current_language])) $term_id = $term_arr[$pll_current_language];
    }

    $children = get_terms($taxonomy, array(
        'parent' => $term_id,
        'hide_empty' => false
    ));

    if ($children) :
        foreach ($children as $subcat) {
            $term_arr[] = $subcat->term_id;
        }
    endif;

    if (is_category($term_arr)) return true;

    if (is_tax($taxonomy, $term_arr)) return true;

    return false;
}
                
            

Eg: elseif (pll_fs_base_is_term_with_child(99)) get_template_part( 'template-parts/posts/archive', 'tuyen-dung' );

Leave a Reply

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.