Home › Forums › Front-end Issues › Display Labels of Checkbox Field
Hello,
I am trying to create an advanced search. So I want to grab all checkbox fields. I don’t want to display it in a post. So I just want to grab the labels of the specific field.
I am trying to make a dropdown to show the labels. So in this, it will grab auto all labels by. Is it possible?
<td><select style="height:30px;">
<option value="">Select City</option>
<option value="">label 1</option>
<option value="">label 2</option>
<option value="">label 3</option>
</select></td>
$field = get_field_object('field_XXX'); // use field key
?>
<select>
<option value="">Select City</option>
<?php
foreach ($field['choices'] as $v => $l) {
?><option value="<?php echo $v; ?>"><?php echo $l; ?></option>
}
?>
</select>
<?php
Trying the above code is causing a warning error to be thrown with my usage and I don’t understand why.
Warning: Invalid argument supplied for foreach()
<?php
$portfolioContent = get_field('portfolio_content'); // this is the group field
if ($portfolioContent) :
$skills = $portfolioContent['skills'];
$field = get_field_object($skills);
?>
<h1><?php echo $subTitle; ?></h1>
<?php
if ($skills) : ?>
<ul>
<?php foreach ($field['choices'] as $v => $l) : ?>
<li><?php echo $l; ?></li>
<?php endforeach; ?>
</ul>
<?php endif;
?>
<?php endif;
?>
$skills = the checkboxes
print_r($skills);
// return value = value
Array ( [0] => wordPress [1] => javascript [2] => jquery [3] => scss [4] => responsive-design [5] => photoshop [6] => illustrator )
// return value = both
Array ( [0] => Array ( [value] => wordPress [label] => WordPress ) [1] => Array ( [value] => javascript [label] => Javascript ) [2] => Array ( [value] => jquery [label] => jQuery ) [3] => Array ( [value] => scss [label] => SCSS ) [4] => Array ( [value] => responsive-design [label] => Responsive Design ) [5] => Array ( [value] => photoshop [label] => Photoshop ) [6] => Array ( [value] => illustrator [label] => Illustrator ) )
$field = get_field_object($skills); <== this needs to be a field key not a field value
The topic ‘Display Labels of Checkbox Field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.