Alexander2014-08-01 14:10:07
Alexander, 2014-08-01 14:10:07

Advanced Custom Fields - how to merge checkboxes?

There is a wordpress site using the ACF (Advanced Custom Fields) plugin - for creating custom fields in posts.
The bottom line is that there are several checkbox fields in the record, which, when displayed, I need to combine into one select field for the user. There can be many such groups of checkboxes - up to 40.
A poor way of output came to mind:

$field1 = get_field('field1');
$field2 = get_field('field2');
$field3 = get_field('field3');
$field40 = get_field('field40);

Get all the values ​​manually, then combine them into an array and enter from the array into the select.
$fields = array($field1,$field2..$field40);
foreach ($fields as $key => $val)
echo '<option  value='.'"'.htmlspecialchars($val).'"'.' >'.$val.'</option>';

But 40 times I don’t want to write this at all.
Can you please tell me how this can be automated?
It is necessary somehow in the for loop (i=1;i<41;i++)..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Alexander, 2014-08-01

$fields = array();
        for ($i = 1; $i < 40; $i++) 
          $fields[$i] = get_field('hotels'.$i);	
foreach ($fields as $key  ){
    foreach ($key as $var  )
    echo '<option  value="'.$var.'">'.$var.'</option>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question