2016-09-06 94 views
0

我在我的wp站点上安装了高级自定义字段类别。但我无法在循环类别中获得字段。代码:WordPress的。如何获得类别中的自定义文件?

$args = array(
    'type'   => 'post', 
    'orderby'  => 'name', 
    'order'  => 'ASC', 
    'hide_empty' => 0, 
    'taxonomy'  => 'catalog' 
); 

    $categories = get_categories($args); 
    if($categories){ 
     foreach($categories as $cat){ 
      echo get_term_meta($cat->cat_ID, 'image_cat',true); //empty 
     } 
    } 

我如何从ACF获取字段?

回答

1
$categories = get_categories($args); 
if($categories){ 
    foreach($categories as $cat){ 
    the_field('image_cat', $cat); 
    } 
} 

如在功能正常的ACF第一值是自定义字段名称和第二个是类别对象

+0

TNX!是工作 ) –

0
$categories = get_categories($args); 
    if($categories){ 
     foreach($categories as $cat){ 
     $taxonomy = $cat->taxonomy; 
     $term_id = $cat->term_id; 

     // load thumbnail for this taxonomy term (term object) 
     $thumbnail = get_field('image_cat', $cat); 

     // load thumbnail for this taxonomy term (term string) 
     $thumbnail = get_field('image_cat', $taxonomy . '_' . $term_id); 
    } 
} 
相关问题