cafe_get_fields()
Purpose
Returns every saved top-level value of an object as an array keyed by field name. Handy for debugging and for passing data to templates or JavaScript.
Syntax
cafe_get_fields( mixed $object_id = null, ?string $object_type = null ): array
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$object_id |
mixed | null |
Which object. null means the current object. |
$object_type |
string|null | null |
Object type, or null to infer it. |
Return value
array<string, mixed>: field name ⇒ formatted value. Only fields with a saved value
are included. An empty array when nothing is saved or the object is unknown.
Example
$fields = cafe_get_fields( $post_id );
foreach ( $fields as $name => $value ) {
printf( '<p><strong>%s</strong>: %s</p>', esc_html( $name ), esc_html( $value ) );
}
Notes
- Uses the same single bulk query as
cafe_get_field(). - Values pass through the same
cafe_field_valuefilters. - Fields that only have a Default Value are not included (they are not saved).