Support

Account

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