benecaster_get_field()
benecaster_get_field( int $field_id, int $object_id ): mixed
Reads one custom field value off one object.
Reach for benecaster_get_fields() first. It takes a group name rather than a numeric field ID and returns everything keyed by field_key, which is both easier to read and more portable — numeric IDs differ between installs, so code written against them breaks the moment it runs on a second site. This function is for when you genuinely have an ID and want one value.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
$field_id |
int |
— | Yes | The field's numeric ID, shown in the ID column of the Field Group editor (Benecaster → Fields → edit a group). This is the ID, not the field_key string — if you have the key, use benecaster_get_fields() instead. |
$object_id |
int |
— | Yes | The post ID of the object whose value you want. |
Return Value
Type:
mixed
The stored value, or null when nothing has been saved for that field on that object. The value passes through the benecaster_field_value filter on its way out, so what you get is what the site displays.
Example
$guest_name = benecaster_get_field( 15, $episode_id );
if ( $guest_name ) {
echo esc_html( $guest_name );
}
Hooks Fired
Need this built rather than just documented? See our services →