We are using an options page and applying a field with a default value to the options page.
If the page has not been saved, there is no data for the field and get_field() is giving an empty response.
I understand that saving the options page will add the default value to the database. However, we would like to have these default values set without any action by the user.
Currently, in our class’s constructor, we are checking to see if the get_field() returns nothing, and updating the field with the default value if it is not already set. However, it seems like this is defeating the purpose of using eh default value setting for the field.
Can ACF be updated to return the default value if there is nothing stored in the database for that field?
This is only an issue for options pages, since regular posts are initially saved when they are created and options pages are not.
If you get the field using the field key it should return the default value.
The problem isn’t so much the missing value as it is the missing field key reference for the value.
I personally have always coded default values in. The reason, I may add fields in the future, these fields will not have values for existing posts. I can never count the data being there, any number of things could cause the value to not be set. But that’s just me.