2016-03-31 10 views
0

私は小さな問題が1つあります。カテゴリページのカテゴリのカスタムフィールドを表示しています。その罰金を示しています。そのカテゴリに投稿がない場合は表示されません。Wordpressは投稿がない場合でもカテゴリフィールドを取得します

私のコードで 'hide_empty' => 0を使用する場所はわかりません。

ここでは、カテゴリのフィールドを表示するために使用したコードです。

$terms = get_the_terms(get_the_ID(), 'category'); 

if(!empty($terms)) { 

$term = array_pop($terms); 
$expert_photo = get_field('expert_photo',$term); 
$expert_name = get_field('expert_name',$term); 
$expert_title = get_field('expert_title',$term); 
$expert_description = get_field('expert_description',$term); 
$expert_introduction = get_field('expert_introduction',$term); 

答えて

0

get_the_terms関数は、投稿に添付されたタクソノミーの用語を取得します。

あなたはすべてのカテゴリを取得したい場合は、このコード

$categories = get_categories(array('orderby'=>'name','hide_empty'=>false)); 
echo "<pre>"; 
print_r($categories); 
を使用することができます
関連する問題