get_categories only getting categories in the main language

I am trying to retrieve in the "content composer" the categories of projects based on the active language. But i only get the categories off the main language, never on the other.

My code is:

Category All

    $categories = get_categories('taxonomy=jw_portfolio_categories');       

                    if(!empty($categories)){
                        foreach($categories as $cat){
                            ?option value="?php echo $cat-term_id; ?"?php echo $cat-name; ?/option?php
                        }
                    }   
    ?
                /select

Any idea on how to get all the categories or the ones of the active language in the WP backoffice?

Topic multi-language categories Wordpress

Category Web


You have to translate your post type and also has to create translated categories for other languages too.


UPDATED, this should work.

<?php
  $category_ID = get_cat_ID ("CategoryName");
  $get_correct_ID_lang = icl_object_id($category_ID, 'category', false)
  $categories = get_categories('child_of=' . $get_correct_ID_lang);
  foreach ($categories as $cat) {
?>
    <a href="<?php echo get_category_link($cat->cat_ID); ?>"><?php echo $cat->cat_name; ?></a>, 
<?php
  }
?>

I have a solution if you are using WPML for the multi-language support, i have used this code before. Modified after your taxonomy.

<?php

//Get categories from current language
//Uses WPML Multi-language

$terms = get_terms('jw_portfolio_categories','hide_empty=1' );

if ( !empty( $terms ) ) {

$term_links = "";

foreach ( $terms as $term ) {

    if( $term->term_id == icl_object_id( $term->term_id,'jw_portfolio_categories', false, ICL_LANGUAGE_CODE ) ) { 
    ?>

        <option value="<?php echo $term->id; ?>"><?php echo $term->name; ?></option>

    <?php
    }
}

echo join( '', $term_links );

}

?>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.