Home › Forums › General Issues › get_field_objects on programtically generated post › Reply To: get_field_objects on programtically generated post
Exactly what I needed. Many thanks.
Do you know if the results of acf_get_field_groups or acf_get_fields are automatically cached in any way or do they always result in a separate db call?
Updated version of my code if it’s useful to anyone:
public static function field_defined($name, $post_id='') {
if(!$post_id){
if (!$post_id = get_the_ID()){throw new Exception("$id must be supplied if called outside of loop");}
}
$groups = acf_get_field_groups(array('post_id' => $post_id));
foreach($groups as $group){
foreach(acf_get_fields($group['key']) as $field){
if($field['name'] == $name){return true;}
}
}
return false;
}
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.