benecaster_get_fields()
benecaster_get_fields( string $group_key, int $object_id ): array
Reads every value in a field group off one object, keyed the way you named the fields.
Address the group by name, not by ID. A group’s numeric ID is local to the install it was created on, so code that hard-codes one works on your site and fails on your client’s. The name travels.
See Custom Fields for the podcaster-facing side of field groups.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
$group_key |
string |
— | Yes | The field group, by name ('Interview Info') or by numeric ID as a string ('5'). Names are matched case-insensitively. Prefer the name — IDs differ between installs. |
$object_id |
int |
— | Yes | The post ID of the object whose values you want. |
Return Value
Type:
array
The group's values keyed by field_key, or an empty array when the group does not exist. Every field in the group is present, including ones with nothing saved — those come back as null rather than being missing, so a key you expect will be there even when the value is not. Each value passes through the benecaster_field_value filter individually.
Example
$interview = benecaster_get_fields( 'Interview Info', $episode_id );
// [ 'guest_name' => 'Sarah Chen', 'booking_url' => 'https://example.com/sarahchen' ]
foreach ( $interview as $key => $value ) {
if ( $value ) {
printf( '<dt>%s</dt><dd>%s</dd>', esc_html( $key ), esc_html( $value ) );
}
}
Hooks Fired
Need this built rather than just documented? See our services →