Skip to main content

benecaster_get_field()

Returns a single custom field value for a given object.

Signature

benecaster_get_field( int $field_id, int $object_id ): mixed

Parameters

Name Type Description
$field_id int The field definition ID from benecaster_fields
$object_id int The post ID of the object to read the value for

Return Value

mixed — the stored value, passed through the benecaster_field_value filter before being returned. Returns null if no value has been saved for this field on this object.

Notes

This is a Free function. It does not require a paid license.

$field_id is the database ID from the benecaster_fields table, not the field_key string. To look up field values by key (e.g. 'guest_name'), use benecaster_get_fields() instead — it returns an associative array keyed by field_key.

The returned value passes through the benecaster_field_value filter. Add add_filter( 'benecaster_field_value', ... ) to transform values at read time — for example, to format a stored date or resolve a stored ID to a label.

Example Usage

Read a single field value by ID and display it:

$guest_name = benecaster_get_field( 15, $episode_id );

if ( $guest_name ) {
    echo esc_html( $guest_name );
}

Include a field value in an RSS custom tag:

add_filter( 'benecaster_rss_extra_item_tags', function ( string $tags, array $episode ): string {
    $sponsor = benecaster_get_field( 22, $episode['id'] );
    if ( ! $sponsor ) {
        return $tags;
    }

    return $tags . '<my:sponsor>' . esc_xml( $sponsor ) . '</my:sponsor>';
}, 10, 2 );