Home Forums Backend Issues (wp-admin) acf/load_field filter question


acf/load_field filter question

  • I am using the acf/load_field filter to convert categories into field-values. I only need to run this code once, then disable it, as the values will be set for the fields.

    The problem is that, for select fields, the choices only remain visible for as long as the filter is in place. If I disable the filter, the value display disappears as well. If I re-enable it, the value is displayed again (i.e., it remains in the database).

    How can I permanently update the ‘choices’ in the field definition?

  • Edit and update the field group that contains the field with the filter in place. This will run the filter on the edit page and populate the choices field. Once you update the field group you should be able to disable the filter.

  • Thanks for the suggestion John, but unfortunately it doesn’t work. The choices section was empty after I removed the filter.

  • that’s odd…

    What version of ACF are you using?

    May sound like a dumb question, but you are removing the filter completely by removing the add_filter() statement right?

  • I’m using ACF Pro v5.3.3.2

    Yes, I have removed the filter by removing the ‘add_filter’ statement 🙂

  • When I follow the steps I gave above it works for me. So now you need to figure out what’s different. The only thing I had running on the test site was ACF5 with and unmodified 2016 theme.

    Do you have a local JSON folder? I don’t really know if this will cause it, but it’s the only other thing I can think of.

  • Thanks for the effort John. I have just tried this on a similar setup to yours – nothing but ACF and an unmodified twentyfifteen theme, and it still doesn’t work.

    One thing that might account for the difference is that I’m trying to update a select within a repeater – would that explain it?

    I don’t have a local JSON folder.

  • Actually, yes, it’s because of the repeater. As soon as I put the select field in a repeater it behaved the same way for me.

    Here’s how to fix it. Before returning the fields update the field and this will force ACF to save the new choices in the database.

      add_filter('acf/load_field/key=field_56abbdb4d9be3', 'dynamic_select');
      function dynamic_select($field) {
        //echo '<pre>'; print_r($field); echo '</pre>';
        $field['choices'] = array(
          'a' => 'A',
          'b' => 'B',
          'c' => 'C',
          'd' => 'D'
        // save new field settings to db
        return $field;
  • That worked! Thanks John 🙂

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘acf/load_field filter question’ is closed to new replies.