2016-09-06 41 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); 
    } 
} 
相關問題