Hi all,
I am trying to check to see if a true/false field exists as I am working with custom WP API routes. For some reason though, the true/false field only returns via get_field in an if statement if it is “ticked” i.e true.
Would you know why this is happening?
Exactly how are you checking if it exists or not, some code might be helpful.
Hey John,
Solved my issues, noticed that update_field() does not work unless it exists. Of course, the field does not exist until something is done with it.
I used the standard update_meta() instead which works fine.
When a field does not exist yet when you update it you must use the field key in update_field() rather than the field name. This is mentioned in the documentation https://www.advancedcustomfields.com/resources/update_field/
The field’s key should be used when saving a new value to a post (when no value exists). This helps ACF create the correct ‘reference’ between the value and the field’s settings.