admin管理员组文章数量:1122846
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?
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 asked Jun 12, 2012 at 19:39 Pedro FerreiraPedro Ferreira 11 silver badge2 bronze badges 03 Answers
Reset to default 0I 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 );
}
?>
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
}
?>
You have to translate your post type and also has to create translated categories for other languages too.
本文标签: getcategories only getting categories in the main language
版权声明:本文标题:get_categories only getting categories in the main language 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284214a1927201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论