2017-04-23 4 views
0

私は常にタクソノミーを嫌い、とても混乱しています。私はACFを使用しています。私はカスタムユーザー登録フィールドの国、コンセント、会社(彼らはすべての分類法です)を呼び出しています。Wordpress - 用語ID(ACF)からタクソミーム名の名前を取得

例:分類=国& TAG_ID = 36 & post_type =会社

$country_tagid = the_field('country', 'user_'.$user_id->ID); //This output 36 
$countrydata = get_terms('country',array('id'=>$country_tagid)); // 
echo $countrydata->name; //return nothing 
$getcountrydata = get_term($country_tagid); 
print ($getcountrydata->name); //return nothing 

それらのすべては、名前を返しませんでした。私はそれが「タイ」を返すと期待しています。なにが問題ですか?

編集: 奇妙なことに、私は手動でユーザーのループの外側に入力しました。

<?php 
    $catinfo = get_term_by('id', 36, 'country'); 
    print $catinfo->slug; //thailand 
?> 

これは機能します。 私は

$country_tagid = the_field('country', 'user_'.$user_id->ID); //This output 36 

ここで何かが間違っている疑いがあるこの行は36が今、私はget_fieldしようとしている印刷します。しかし、それはこれを試して

答えて

0

ARR私を返す: https://developer.wordpress.org/reference/functions/get_terms/

$countrydata = get_terms('country',array('include' => array($country_tagid)); 

//

get_termsのためのあなたの構文が間違っていると思います。

+0

$ countrydata = get_terms」をcountry '、array(' include '=>配列($ country_tagid))); print_r($ countrydata); Array()を返します。 –

0

この行が間違っていることがわかりました。変数に値36を格納しませんでした。代わりにそれを表示します。

$country_tagid = the_field('country', 'user_'.$user_id->ID); //This output 36 

代わりにget_fieldに変更されました。

$country_tagid = get_field('country', 'user_'.$user_id->ID); //This output 36 

私はその後で国の名前を取得

$countryid= $country_tagid[0]; 

でIDを取得:だから

$catinfo = get_term_by('id', $countryid, 'country'); 
$countryname= $catinfo->name; 

フルコード:(

$country_tagid = get_field('country', 'user_'.$user_id->ID); 
$countryid= $country_tagid[0]; 
$catinfo = get_term_by('id', $countryid, 'country'); 
$countryname= $catinfo->name; 
関連する問題