Select Page
Programatic ACF Locations

Now i am using ACF for front end forms a lot more i needed to show the same form with different fields based on location

add_filter('acf/get_field_group', 'my_change_field_group');
function my_change_field_group($group) {

   $pid = get_the_ID();

   if (  $pid == 2218 && $group['key'] == 'group_600157285d7a9'  ) {
      $group['location'] = array(
         array(
            array(
               'param' => 'user_form',
               'operator' => '==',
               'value' => 'register',
            ),
         ),
      );
   }
   return $group;
};

In this example basically if the page id is X add fields to user_form for a specific group ID

Preloader