• Hi,
    I am using a custom taxonomy with few terms, translated into three languages. I only want to get the terms in the current language, so I am doing this:

    
    $options = array(
    	'taxonomy' => 'event_category',
    	'hide_empty' => false
    );
    if (function_exists('pll_current_language')) {
    	$options['lang'] = pll_current_language();
    }
    $terms = get_terms($options);
    

    The $options array then includes ‘lang’ => ‘de’, but I am getting ALL the existing terms anyway. Doesnt matter what I use as the lang parameter, I am getting all the taxonomy terms in the database for the ‘event_category’ taxonomy.

    Is this a bug?

    • This topic was modified 7 years, 3 months ago by KlaRo.
    • This topic was modified 7 years, 3 months ago by KlaRo.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter KlaRo

    (@klaro)

    I have ‘Custom Taxonomy Order NE’ plugin installed and as that might change how the query works, I have disabled it – it didnt help with the issue above.

    Isu

    (@isuke01)

    does you use Polylang or polylang pro ?

    Thread Starter KlaRo

    (@klaro)

    Regular version, not the pro one.

    Isu

    (@isuke01)

    Sorry, I noticed this issue after installing pro, but on other website, I had same error, and my friend to.
    Wierd thing is

    https://polylang.pro/doc/developpers-how-to/

    says it should work. And it worked. Then it stopped.
    It seems to be a some kind of bug.
    I also want point – I use it in WP REST.
    I fixed it using:

    
    $positions_tax = get_terms( 'pos', $args );
    if($positions_tax){
            foreach ($positions_tax as $key => $tax) {
                if(pll_get_term_language($tax->term_id) !== $args['lang']){
                    unset($positions_tax[$key]);
                }
            }
            $positions_tax = array_values($positions_tax);
        }

    Sorry for late answer ??

    Thread Starter KlaRo

    (@klaro)

    Oh yes, loading all the terms/posts and then filtering them manually works, thanks for the useful snippet!

    But I am very surprised there is no response/fix from the plugin author, this seems like a rather serious and annoying bug to me.

    Has this been fixed?I don’t see it working in polylang ( free version )

    Any soon plans to solve this? same issue here.

    • This reply was modified 6 years, 8 months ago by Ali Basheer.

    Still an issue today as it seems. I have the issue with MetaBox plugin, all languages are showing when I add

    'query_args' => array(
        'lang' => 'en'
    )

    I don’t want to edit the metabox plugin with the solution from @isuke01 so I have fixed it with the following hook:

    add_filter('get_terms' , 'pll_get_terms_fix', 10, 4);
    function pll_get_terms_fix($terms, $taxonomy, $query_vars, $term_query)
    {
        if(in_array('mytaxonomy',$taxonomy) && function_exists('pll_get_term_language') && isset($query_vars['lang'])){
            foreach ($terms as $key => $term) {
                if($term->taxonomy == 'mytaxonomy' && pll_get_term_language($term->term_id) !== $query_vars['lang']){
                    unset($terms[$key]);
                }
            }
            $terms = array_values($terms);
        }
        return $terms;
    }
    • This reply was modified 6 years, 5 months ago by Samuel Diethelm. Reason: typo
    Plugin Author Chouby

    (@chouby)

    Hi,

    I just tested in Polylang 2.3.10

    
    get_terms( array( 'taxonomy' => 'category' ) ); // returns terms in the current language
    get_terms( array( 'taxonomy' => 'category', 'lang' => '' ) ); // returns all languages
    get_terms( array( 'taxonomy' => 'category', 'lang' => 'en' ) ); returns terms in English
    

    They all work as expected.

    @chouby, have you tried with a custom taxonomy?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘get_terms() ignores ‘lang’?’ is closed to new replies.