Home › Forums › General Issues › Set field group programatically › Reply To: Set field group programatically
This fixed it which means I was wrong in my assumptions above. I just basically overwrote the existing locations array and everything works fine:
add_filter( 'acf/validate_field_group', 'add_custom_location_dynamic', 10, 1 );
function add_custom_location_dynamic( $field_group ) {
if ( $field_group['key'] === 'group_6786e0728946a' ) {
// This line below clears any existing locations
$field_group['location'] = array();
$currentYear = get_field('current_year', 'option');
$awardArgs = createYearArray($currentYear);
// $awardArgs is just an array of ["2024", "2025"]
$x=0;
foreach($awardArgs as $year) {
$field_group['location'][$x][] = array(
'param' => 'post_type',
'operator' => '==',
'value' => 'entrant_'.$year,
);
$x++;
}
}
return ($field_group);
}
Hope that helps anyone else looking for this.
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.