2016-09-06 5 views
0

私はwp-siteのAdvanced Custom Fieldsカテゴリにインストールされています。しかし、私はループのカテゴリでフィールドを得ることができませんでした。コード:ワードプレス。カテゴリでカスタムファイルを取得する方法?

$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最初の値のカスタムフィールド名で2つ目は、カテゴリオブジェクト

+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); 
    } 
} 
関連する問題