Home › Forums › Bug Reports › 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.
Cheers!
Phill
Hi @Phillip
Thanks for the bug report.
That line should be return false
, I’ve fixed this and re-pushed the plugin to wordpress.org
Hopefully not too many people experience this PHP notice and I can get away without a new version release for now.
Thanks
E
Hi Elliot
Major problems here.
I was seeing the error too in debug mode, so downloaded the new version you pushed to WP.org.
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.
HELP!
In case it helps: [www.]ellaberthoud.com/2013/
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.
Cheers
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?
Thanks
E
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.
James
wp_postmeta for post id 4 (my homepage):
a:26:{i:0;s:11:"large_image";i:1;s:11:"small_quote";i:2;s:11:"small_image";i:3;s:11:"large_quote";i:4;s:14:"portrait_image";i:5;s:14:"portrait_image";i:6;s:11:"small_image";i:7;s:14:"portrait_image";i:8;s:14:"portrait_image";i:9;s:11:"large_image";i:10;s:7:"twitter";i:11;s:9:"listening";i:12;s:7:"reading";i:13;s:9:"news_feed";i:14;s:11:"large_quote";i:15;s:16:"recommended_read";i:16;s:8:"big_link";i:17;s:11:"small_image";i:18;s:16:"little_link_wide";i:19;s:11:"little_link";i:20;s:11:"little_link";i:21;s:11:"little_link";i:22;s:8:"big_link";i:23;s:11:"little_link";i:24;s:8:"big_link";i:25;s:11:"little_link";}
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!
Thanks
James
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
Thanks
E
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?
Thanks
E
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:
Yet, those broken fields still appear in the front end, as blank boxes:
[http://www.]ellaberthoud.com/2013/ – 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?
Thanks
James
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?
Thanks
E
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.
James
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.
Thanks
E
The topic ‘Undefined Variable 'value' in api.php’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.