Home › Forums › ACF PRO › Check if field key exist › Reply To: Check if field key exist
Is there a possibility that none of them will exist?
I would do something like this
$possible = array('field_5b5b34f4ed085', 'field_5b5b34f4ed085', 'field_5b5b34f4ed085');
$field_key = false;
$field = false;
foreach ($possible as $key) {
$field = get_field_object($key);
if ($field) {
$field_key = $key;
break; // causes exit of loop when field is found
}
}
// if field is not found
// $field_key and $field will both == false
// if field is found
// $field_key == the existing field key here
// $field == existing field object
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.