2014-04-28 3 views
1

필드의 리피터 필드 유형을 사용하고 있습니다. 상위 필드 이름은 'map_details'이고 하위 필드 이름은 선택 드롭 다운 목록 인 'name_of_county'입니다.고급 사용자 정의 필드의 선택 상자 값 가져 오기

지금은 frontend.My 코드에서 그 선택 상자의 모든 값을 표시 할 내가 기본적으로 인 부모가 아닌 서브 필드의 필드 키를 준대로 작동하지 않습니다

$field_key = "field_535befe551ba5"; //field key of parent 
$field = get_field_object($field_key); 

if($field) 
{ 
    echo '<select name="' . $field['key'] . '">'; 
     foreach($field['choices'] as $k => $v) 
     { 
      echo '<option value="' . $k . '">' . $v . '</option>'; 
     } 
    echo '</select>'; 
} 

입니다 상자를 선택하십시오. 또한 하위 필드의 필드 키를 찾을 수 없습니다.

어떻게 프런트 엔드에 값과 키가있는 하위 필드 드롭 다운 상자를 표시 할 수 있습니까?

답변

1

최근에 프론트 엔드에서 값/키를 출력하는 방법을 찾았습니다 : 이런 경우에 나는 무엇이 진행되고 있는지 이해하기 위해 항상 print_r 부모 배열 ('pre'태그 사이)을 신뢰합니다 ... 도움이됩니다. 리피터와 마찬가지로 는 선택 필드 (sub_field는) 그래서, 배열에서 한 단계 더 깊다 :

$field_key = "field_535befe551ba5"; //field key of parent 
$field = get_field_object($field_key); 

if($field) { 

    // As explained, it's better to first take a look to 
    // the array's structure. Uncomment the next 3 lines 
    // to print it in a pretty way 

    // echo '<pre>'; 
    // print_r ($field); 
    // echo '</pre>'; 

    foreach ($field['sub_fields'] as $the_subfield) { 
     $the_subfield_name = $the_subfield['name']; 

     // in case that you have more than one subfield in the repeater 
     // we need to check that we are in the desired subfield: 
     if ($the_subfield_name == 'name_of_the_subfield') { 
     //in your case: 'name_of_country' 

      // now that we are sure that we are inside the desired 
      // subfield, we will output the different choices available 
      echo '<select name="' . $the_subfield['name'] . '">'; 
      foreach($the_subfield['choices'] as $k => $v) { 
       echo '<option value="' . $k . '">' . $v . '</option>'; 
      } 
      echo '</select>'; 
     } 
    } 
} 

나는 그것이 도움이되기를 바랍니다!

관련 문제