Home Forums Bug Reports Undefined Variable 'value' in api.php


Undefined Variable 'value' in api.php

  • Hey Elliot, small bug thats causing Notices when you have PHP error reporting turned on.

    File: advanced-custom-fields/core/api.php
    Line 636 (inside get_sub_field)

    // return false
    return $value[ $i ][ $field_name ];

    Neither $i or $value appear above in the function, so not sure if you’ve pasted this from another function by accident.


  • Hi @Phillip

    Thanks for the bug report.

    That line should be return false, I’ve fixed this and re-pushed the plugin to

    Hopefully not too many people experience this PHP notice and I can get away without a new version release for now.


  • Hi Elliot

    Major problems here.

    I was seeing the error too in debug mode, so downloaded the new version you pushed to

    I then go to my site and 50% of the fields on a massive flexible content field have disappeared from the page editor and ACF editor – they’re all fields that have image fields.


  • In case it helps: [www.]

    That grid of boxes is controlled by a flexible content field.

    All the blank ones were images! Every single image related field has disappeared in the backend and there is no sign of them in the front.


  • Hi @jamblo

    Can you confirm 100% that it was updating to 4.3.0 for the second time that has caused this issue? Did your image field display before?

    How did you re-update to v4.3.0?

    If you edit your field group, is the image sub field available?
    If you edit your post, does the image sub field appear? What does it look like?

    Can you check your DB for the values in the wp_postmeta table? Are the values for the flexible content field visible?


  • Hi Elliot

    Here’s the process I went through:

    1. Added a new field with a select drop down (with 1,2,3 as the options). Stuck “1” in the default field, saved and then added a field of this type to the homepage. At this point I saw the error (debug mode true) for the first time. Images were still there. I commented out my code pulling in the new field and the error (as outlined by the original poster) disappeared. Figured there was an issue with using “1” as the default number. Deleted the select drop down sub field and created a radio one instead, with no default declared. Refreshed the post editor, chose the radio button options that were needed and saved. Error was there again on front end.

    2. Googled the error, found this thread. Downloaded the latest version of ACF and uploaded through the plugins uploader in WP admin. Error on upload as plugin already exists. Go to FTP, rename old ACF folder and upload unzipped new files. Go to homepage, errors gone, all images gone. Rename new ACF folder, go to plugins, Add new, find ACF, install… No change.

    3. Go to page editor, half the fields are missing from the list, no fields with image field available from flexible field add panel. Go to ACF editor and my flexible field, all fields with image includes gone. Do not, at any point press save/submit, so am sure the data is still there – especially as the homepage is still showing the empty space where the fields were before this happened. Go back to this thread, find original code (that the update fixed) edit api.php file to display old code, refresh homepage, errors back, images still broken. Undo api.php change.

    To answer your questions:

    If I go to create a new flexible field it will not let me create ANY sub fields. If I go to edit my existing flexible content field I cannot add any new fields. The duplicate, etc. links on the left are gone too. In the post editor, all flexible content fields that have an image field are gone.

    I can’t check the db right now as need to get access, but the fact the boxes still appear in the page (and the text data shows for those entries, just not the images) would suggest to me that the data is still in the db.

    I hope that helps. It’s 1am so I’m. Going to sleep, back online in 7/8 hours. You’re welcome to login to my site if you want. Just send me an email.


  • @elliot

    wp_postmeta for post id 4 (my homepage):


    That is the correct order they are supposed to display – note large_image, followed by small_quote – so I guess all is well in terms of the database.

    Looking forward to your thoughts!


  • Hi @Phillip

    Your value above shows all the values as a serialized array. Is this correct?
    Was this from a var_dump or is this the only value in the DB?

    Can you please provide some login details here? You can use the ‘private reply’ options to hide the details


  • This reply has been marked as private.
  • Hi @jamblo

    I logged in and had a look at the home page. All the data is there exept the images, so I don’t understand how your data could be saved as a serialized array as previously posted.

    Have you tried re-selecting the images for each image field?
    Have you re-saved the home page yet?
    Do you have any code which could be hooking into any ACF filter / action?


  • This reply has been marked as private.
  • This reply has been marked as private.
  • Hi @Phillip

    Most likely because this is your thread…

    Thanks for the warning

  • Hi @jamblo

    I can see the image fields just fine as shown in this attachment

  • Yeah, it looks like some are still hanging about there, but several have disappeared entirely from the ACF editor and are not in the “add repeater” section:

    ACF Flexible Content - options missing

    Yet, those broken fields still appear in the front end, as blank boxes:
    [http://www.] – and in the postmeta in the database, as outlined above.

    Is there any way of retrieving this field data? Can you see it in the mysql database? Should I just give up and start again?


  • Hi @Phillip

    It is hard for me to guess which is missing and which isn’t
    Can you please provide very clear instructions as to what exactly has changed?

    What do you mean by:
    “but several have disappeared entirely from the ACF editor”

    Also, what do you mean by:
    “and are not in the “add repeater” section:”

    I removed your mysql data from this post for security reasons, so I can’t access your DB data. Perhaps you could look at the postmeta table and take a screenshot of all the postmeta data for the home page ID?


  • The image-related sub-fields had disappeared from where you create them… eg.

    WP Admin > Custom Fields > “Front Page Boxes” > Flexible Content Field.

    They had also disappeared from Pages > Edit > Front Page > “Front Page Boxes” FCF.

    Yet, they still appeared on the front-end and the database (as above), until I pressed update.

    Anyway, I gave up trying to explain what was wrong and have just spent two hours creating it all again.

    Thanks for trying to help. There was obviously an error that corrupted it all, but not knowledgeable enough on the mechanics to put my finger on it.


  • Hi @jamblo

    Thanks for the follow up. Glad you got it working again.
    Yes, this must have unfortunately been some sort of corruption.

    Although I can’t provide any help just yet, I can assure you that this kind of issue won’t be a problem in ACF v5!

    v5 introduces a new data structure for sub fields which will make for a much more reliable plugin!

    Should be released in a few months.


  • Looking forward to it! Cheers.

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

The topic ‘Undefined Variable 'value' in api.php’ is closed to new replies.