Home › Forums › Backend Issues (wp-admin) › Saving Default Value to Custom Fields › Reply To: Saving Default Value to Custom Fields
The way ACF works, it cannot associate a field with a post when getting a field value. get_field() is just a wrapper for get_post_meta() and it is the same for all acf functions. ACF does not know that a field group is related to a certain location except when editing that location.
The location rules are complicated and what your expecting is that ACF will check the location rules for every field group every time you use get_field(). That would be simply impossible, it would time out the load of every page.
ACF is also not going to retroactively find every post, term, or options page that might be associated with a field group when you save the field group. Again, this would be impossible and will likely time out update process.
There are some things in WP that it is not possible to do using the functions that WP supplies. The only way to do these things would be if the developer of ACF build a custom interface to deal with the database and to manage the things that WP is already managing.
As has been said many times in many other posts on this forum. ACF uses existing WP functions. If you did
get_post_meta($post_id, $field_name, true)
and there is nothing stored in that field then it will return nothing. This is all that ACF is doing. If you want there to be a default value then you need to code that default value in.
$value = get_post_meta($post_id, $meta_key, false);
if (!$value) {
$value = 'default value';
}
Hope that helps explain it.
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.