I’m using ACF PRO version 5.7.9.
I have a metabox with ‘select’ field named “Country”. I set this field return format is ‘Both(Array)’.
When I use this code var_dump(get_field('country',$post_id));. It returns an array.
I deleted and created “Country” field again and use this code var_dump(get_field('country',$post_id));. Now it returns an string value.
In order to fix this issue, I have go to the post edit screen, and click on “update” button, so that var_dump(get_field('country',$post_id)); will return array again.
But I have many posts and I can not click update for each post. I realised that posts which are created before I deleted and created “Country” field will get this issue. So How can I solve it.
The reason this happened is because you deleted the field and created it again. This caused the ACF field key reference for any values saved to the field to be incorrect, it points to the old field key that no longer exists. Because of this ACF does not know what to do with the value stored in the database so it returns what is stored without formatting it. The only way to fix this is to update all the field key references, which means that you need to update all posts,
Or you can alter it by doing a query on the DB UPDATE wp_postmeta SET meta_value = "NEW FIELD KEY" WHERE meta_value = "OLD FIELD KEY"
Please back up your DB before making changes like this.