Home › Forums › Add-ons › Options Page › Passing Options Repeater through to Field Group Checkboxes
Hello,
function.php code:
// Add Technology Page Options to Technology Field Group
function my_acf_load_field( $field )
{
// reset choices
$field['choices'] = array();
// load repeater from the options page
if(get_field('technology', 'option'))
{
// loop through the repeater and use the sub fields "value" and "label"
while(has_sub_field('technology', 'option'))
{
$value = get_sub_field('technology_page_link');
$label = get_sub_field('technology_name');
$field['choices'][ $value ] = $label;
}
}
// Important: return the field
return $field;
}
// v3.5.8.2 and below
add_filter('acf_load_field-report_technology_pages', 'my_acf_load_field');
// v4.0.0 and above
add_filter('acf/load_field/name=report_technology_pages', 'my_acf_load_field');
For anyone having similar issues here is the solution…
<?php
$field = get_field_object('report_technology_pages');
$technologies = get_field('report_technology_pages'); // array of selected technology values ?>
<ul>
<?php foreach($technologies as $technology){ ?>
<li><a href="<?php echo $technology; ?>"><?php echo $field['choices'][ $technology ]; ?></a></li>
<?php } ?>
</ul>
</div>
I was having the illegal offset type error when trying to get labels using the method documented in Resources, and your solution fixed it. Thanks!
You must be logged in to reply to this topic.
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.