Home Forums Front-end Issues get_field arbitrarily not returning value


get_field arbitrarily not returning value

  • Using ACF PRO 5.5.7 with WP 4.7.2. Rolling back to ACF 5.5.3 does not fix.

    I have a function to which I pass a $post object and have simplified the function to isolate the problem:

    printLinkBar($post) {
      echo '<pre>';
      echo '<h2>' . $post->ID . '</h2>';
      $source = get_field('source', $post->ID);
      echo 'source: ' . $source . '<br>';
      $source2 = get_field('field_561ef519ecce4', $post->ID); // Key refers to 'source' field
      echo 'source2: ' . $source2 . '<br>';
      $all = get_fields($post->ID);
      echo '</pre><hr>';

    I call this function repeatedly and not from within the_loop. It is always passed a post that is a custom post type.

    The first time it is called, it does not output the value for the ‘source’ field and the field is missing in the value returned by get_fields.

    When a newer post is created, that newer post will not have these values output and the post that didn’t work works.

    The value of the field always shows up as expected in the admin.

    Calling setup_postdata() doesn’t fix things.

    Changing the name of the field to source2 or source3 does not fix the problem.

    Simply visiting the post in the admin *sometimes* fixes it, but not always. This post type is created outside of the admin so usually they are never seen within the admin.

  • How are the fields set/updated in not in the admin? Example of code used to update the fields?

    Do you have a caching plugin or some other caching system running on the site?

  • Updating to 5.5.8 – released today – seems to have fixed the issue, but answering anyway:

    Registered users can create CPTs from a form on the front end. The line that attaches the custom field to the CPT is

    update_field('field_561ef519ecce4', $_REQUEST['directory-link-source'], $post_id;

    The site uses W3 Total Cache for caching but this problem happened when the plugin was disabled, however after I disable W3TC, I must disable ACF Pro before I am able to re-activate W3 TC.

    I’ve spent way too much time on this issue to further nail down exactly what was going on. I’m just crossing my fingers. But if I can help solve a problem for someone else, I would be happy to to some tests to further isolate the problem.

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

The topic ‘get_field arbitrarily not returning value’ is closed to new replies.