2017-04-23 14 views
0

나는 분류법이 항상 싫지만 너무 혼란 스럽습니다. 나는 ACF를 사용하고있다. 나는 사용자 정의 사용자 등록 필드를 국가, 콘센트, 회사 (그들은 모두 택 소노 미)라고 부른다.Wordpress - 용어 ID (ACF)에서 분류 이름의 이름을 가져옵니다.

예 :

$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 

그들 모두 분류 = 국가 & tag_ID = 36 & post_type = 회사 이름을 반환하지 않았다. 나는 그것이 '태국'을 반환 할 것으로 기대합니다. 뭐가 잘못 되었 니?

편집 : 이상한, 수동으로 사용자의 루프 외부에 입력했습니다.

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

이것은 작동합니다. 뭔가가 (36)가 지금은 get_field하기 위해 노력하고있어이 줄을 인쇄 여기

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

잘못 생각한다. 하지만 그것은 나를

답변

0

이 시도, 언 반환 : //

https://developer.wordpress.org/reference/functions/get_terms/

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

는 get_terms에 대한 구문이 잘못 생각합니다.

+0

$ countrydata의 =의 get_terms ('

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

나는 그때까지 나라 이름을 검색

$countryid= $country_tagid[0]; 

에 의해 ID를 검색 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로 변경되었습니다. 그래서

$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;