Home › Forums › General Issues › [Checkbox] How to display all item as check uncheck › Reply To: [Checkbox] How to display all item as check uncheck
I have been trying to get this code to work but I keep getting an error “Trying to access array offset on value of type bool on line 110”. My checkbox field name is available_features and it is a sub field in a group name tier. I have tried both codes:
Version 1:
<?php
$tier = get_field('tier');
$values = get_field($tier['available_features']);
$field = get_field_object($tier['available_features']);
$choices = $field['choices']; // This is the line 110 that keeps throwing the error ?>
<?php foreach($choices as $choice => $label) : ?>
<?php foreach ( $values as $value ) : ?>
<?php if( $value['value'] == $choice ) {
$status = 'available';
}
else {
$status = 'unavailable';
} ?>
<?php endforeach; ?>
<li class="<?php echo $status;?>"><?php echo $label;?></li>
<?php endforeach;?>
Version 2:
<?php
$tier = get_field('tier');
$values = get_field('available_features'); // This is the difference in V1 and V2
$field = get_field_object('available_features'); // This is the difference in V1 and V2
$choices = $field['choices']; // This is the line 110 that keeps throwing the error ?>
<?php foreach($choices as $choice => $label) : ?>
<?php foreach ( $values as $value ) : ?>
<?php if( $value['value'] == $choice ) {
$status = 'available';
}
else {
$status = 'unavailable';
} ?>
<?php endforeach; ?>
<li class="<?php echo $status;?>"><?php echo $label;?></li>
<?php endforeach;?>
I have also tried both with “get_sub_field” and “get_sub_field_object”. I keep running into the same error.
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.