Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

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

}

?>
share|improve this answer
    
Thanks for the quick response. –  Pedro Ferreira Jun 12 '12 at 21:02
    
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? –  Pedro Ferreira Jun 12 '12 at 21:04
add comment

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
  }
?>
share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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