0

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?

0
0

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 );

}

?>
1
  • I am using WPML but i get the same behavior. get_terms('jw_portfolio_categories','hide_empty=1' ); only gets the default language categories. Even if i change (in the BO) to other (say Portuguese) it only shows the english categories. Could it be some setting of the plug-in? Jun 12 '12 at 21:04
0

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
  }
?>
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.