Pods::has PHP Method

has() public method

Check if an item field has a specific value in it
Since: 2.3.3
public has ( string $field, mixed $value, integer $id = null ) : boolean
$field string Field name
$value mixed Value to check
$id integer (optional) ID of the pod item to check
return boolean Whether the value was found
    public function has($field, $value, $id = null)
    {
        $pod =& $this;
        if (null === $id) {
            $id = $this->id();
        } elseif ($id != $this->id()) {
            $pod = pods($this->pod, $id);
        }
        $this->do_hook('has', $field, $value, $id);
        if (!isset($this->fields[$field])) {
            return false;
        }
        // Tableless fields
        if (in_array($this->fields[$field]['type'], PodsForm::tableless_field_types())) {
            if (!is_array($value)) {
                $value = explode(',', $value);
            }
            if ('pick' == $this->fields[$field]['type'] && in_array($this->fields[$field]['pick_object'], PodsForm::simple_tableless_objects())) {
                $current_value = $pod->raw($field);
                if (!empty($current_value)) {
                    $current_value = (array) $current_value;
                }
                foreach ($current_value as $v) {
                    if (in_array($v, $value)) {
                        return true;
                    }
                }
            } else {
                $related_ids = $this->api->lookup_related_items($this->fields[$field]['id'], $this->pod_data['id'], $id, $this->fields[$field], $this->pod_data);
                foreach ($value as $k => $v) {
                    if (!preg_match('/[^0-9]/', $v)) {
                        $value[$k] = (int) $v;
                    } else {
                    }
                }
                foreach ($related_ids as $v) {
                    if (in_array($v, $value)) {
                        return true;
                    }
                }
            }
        } elseif (in_array($this->fields[$field]['type'], PodsForm::text_field_types())) {
            $current_value = $pod->raw($field);
            if (0 < strlen($current_value)) {
                return stripos($current_value, $value);
            }
        } else {
            return $this->is($field, $value, $id);
        }
        return false;
    }