2016-08-03 28 views
0

已經四處奔波,無法使其工作 - 可能是一件很簡單的事情,但我沒有留下任何頭髮 - 任何人都可以幫助我嗎?ACF - 獲取靈活內容字段中的複選框值

<?php 
if(have_rows('page_content')): 
while (have_rows('page_content')) : the_row(); 

    if(get_row_layout() == 'specs'): 

     // check if the nested repeater field has rows of data 
     if(get_sub_field('objectives')): 
     echo '<ul>'; 
     $field = get_field_object('objectives'); 
     $value = $field['value']; 
     $choices = $field['choices']; 

      // loop through the rows of data 
      foreach($value as $v): 
       echo '<li>'.$choices.'</li>'; 

      endforeach; 
      echo '</ul>'; 
     endif; 
    endif; 
endwhile; 
endif; 
?> 

在此先感謝。

回答

0

工作,現在......由於在ACF的大力支持團隊。 。$選項後缺少[$ v]。工作代碼如下:

<?php 
if(have_rows('page_content')): 
while (have_rows('page_content')) : the_row(); 

if(get_row_layout() == 'specs'): 

    // check if the nested repeater field has rows of data 
    if(get_sub_field('objectives')): 
    echo '<ul>'; 
    $field = get_field_object('objectives'); 
    $value = $field['value']; 
    $choices = $field['choices']; 

     // loop through the rows of data 
     foreach($value as $v): 
      echo '<li>'.$choices.'</li>'; 

     endforeach; 
     echo '</ul>'; 
    endif; 
endif; 
endwhile; 
endif; 
?> 
0

你可以嘗試用這樣的ACF領域的重點,

$field_key = "field_5039a99716d1d"; 
$field = get_field_object($field_key); 

https://www.advancedcustomfields.com/resources/get_field_object/

+0

謝謝Khushi,但沒有工作 - 我更新代碼,以包括字段鍵,但沒有改變。 – Renegade

+0

你能告訴我你在$ field數組中獲得什麼嗎? – khushi

+0

看到這個鏈接可能會幫助你[瞭解更多](https://support.advancedcustomfields.com/forums/topic/repeater-field-and-checkbox/) – khushi