Support

Account

Home Forums General Issues Field is not loaded / load_field doesn't properly initialize

Solving

Field is not loaded / load_field doesn't properly initialize

  • Hi,

    I am using version 4.4.11.
    I am currently running into the following problem.

    1. I try to get the value of a field (get_field()).
    2. The function get_field_object() calls the action “acf/load_field” in line 278.

    Now we are inside of core/fields/_functions.php.

    3. the wp_cache_get() call fails, $field === false.
    4. nothing is loaded from the db block, so $field still false after line 380
    5. now the action acf/load_field_defaults is called with false as parameter.
    6. this returns the blank field array, with no actual values set (so $field["name"] === "" for example.
    7. in line 388+ nothing is actually set, as the parameters are all empty.

    So it seems that there is a bug anywhere in the code.

    The exact same code is running on the dev machine, but not on the production machine with a cloned database. Are there some caching issues or anything else, that I should be aware of?

    Thanks for any help.

    Cheers
    Jannik

  • (I also posted this as support ticket, as I actually missed the notice on top before sending)

  • What kind of field is not being returned?

  • Hi,

    these were all simple text fields.
    I refactored the code now and everything works differently now, so I can’t tell you how it went wrong in full detail.

    All I know is that – as described above – if the call to wp_cache_get() fails (for whatever reason), the whole field doesn’t work.

    Maybe a simple sanity check would fix this issue here – as a precaution to “not fully trust the WP cache”.

    Cheers
    Jannik

  • I’m having a similar issue with the acf/load_field hook, though it seems like the data for the select is working properly the select2 script isn’t initializing. I have a Select field within a Flexible Content / Repeater that loads icons from a CSS file:

    add_filter( 'acf/load_field/key=field_58a4b7d2dc743', function( $field ){
      $stargate = file_get_contents( get_template_directory() . '/assets/styles/icons/stargate.css' );
      preg_match_all( '/\.(.*):before/', $stargate, $choices );
      $choices = $choices[1];
      $field['choices'] = array(
        '' => ''
      );
      if( $choices ){
        sort( $choices );
        foreach( $choices as $choice ){
          $field['choices'][$choice] = $choice;
        }
      }
      return $field;
    } );

    which seems to be working, because my select markup contains the correct options:

    <select id="acf-field_57ab771f7670b-6-field_57ae32e9ae604-58e285a16d10a-field_58a4b7d2dc743" class="" name="acf[field_57ab771f7670b][6][field_57ae32e9ae604][58e285a16d10a][field_58a4b7d2dc743]" data-ui="0" data-ajax="0" data-multiple="0" data-placeholder="Select" data-allow_null="0" tabindex="-1" title="Icon" style="display: none;">
      <option value="" selected="selected" data-i="0" class=""></option>
      <option value="zsg-arrow-left-parc">zsg-arrow-left-parc</option>
      <option value="zsg-arrow-right-parc">zsg-arrow-right-parc</option>
    </select>

    however the select2 container is not enabled and has the .select2-container-disabled class. If I update the post, that select works fine. In fact this whole field was working properly but possibly stopped working with a recent update?

  • I can’t say what is causing the issue. It could be a conflict with another plugin. Have you tried deactivating other plugins? Especially any other plugin that uses select2. There are some known conflicts with different plugins loading different versions of select2.

    You also say that this is a select field. Do you know what version of PHP your running on the problem site?

  • You know what, it was totally my fault. I wasn’t using the ACF JavaScript hooks, switched to those and it’s working great.

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

You must be logged in to reply to this topic.