Skip to main content

benecaster_field_value

Filter Free Since v1.0.0

Filters a custom field value before it is returned to the caller. Fires on every field value read — from `benecaster_get_field()`, `benecaster_get_fields()`, and the REST endpoint that loads field values for the editor. When `benecaster_get_fields()` is called for a group, this filter fires once per field in the group.

This is a display-only transformation — the stored database value is unchanged. Use it to format raw stored values into display-ready output, such as converting a stored date string to a localized format or rendering Markdown as HTML. This filter fires on every read including every episode editor load, so keep callbacks fast and avoid external API calls.

Parameters

Name Type Default Description
$value mixed Raw stored field value
$field_id int ID of the custom field
$object_id int ID of the object the field belongs to (e.g. episode post ID)
$cpt_slug string The CPT slug (e.g. 'benecaster_episode')

Returns: mixed

Examples

Render Markdown field as HTML for one field

add_filter( 'benecaster_field_value', function( $value, $field_id, $object_id, $cpt_slug ) {
    // Convert a stored Markdown field to HTML for a specific field ID.
    if ( 42 === $field_id && 'benecaster_episode' === $cpt_slug ) {
        return wp_kses_post( wpautop( $value ) );
    }
    return $value;
}, 10, 4 );

Format stored date as localized date string

add_filter( 'benecaster_field_value', function (
    mixed  $value,
    int    $field_id,
    int    $object_id,
    string $cpt_slug
): mixed {
    // Only apply to the specific date field.
    if ( 42 !== $field_id || null === $value ) {
        return $value;
    }

    $timestamp = strtotime( (string) $value );
    if ( false === $timestamp ) {
        return $value;
    }

    return date_i18n( get_option( 'date_format' ), $timestamp );
}, 10, 4 );

Notes

This filter fires on every field value read, including during editor load — keep callbacks fast and avoid slow operations such as external API calls or uncached database queries. Transformations here are for display only; the stored database value is unchanged. This is a Free filter — it fires regardless of license status.