Skip to main content

React to episode custom field changes from an add-on

Free Beginner

Fires when custom field values on an episode are saved and at least one value actually changed, whether the podcaster saved the episode editor or an importer or add-on wrote the value with benecaster_update_field(). It does not fire on saves where nothing changed, so you can act on every invocation without diffing yourself.

When it fires, you receive an array identifying which fields changed — use it to target specific fields rather than re-reading everything. Typical uses: sync episode content to an external CMS, warm a page cache, or trigger a workflow when a specific field is updated.

When to Use This

Use this hook when:

  • Your add-on syncs episode data to an external service and only needs to act when specific fields change

  • You want to trigger a workflow (cache invalidation, webhook, notification) after the podcaster updates custom metadata

  • You’re building an integration that reads Benecaster custom fields and needs to stay in sync

This hook fires for benecaster_episode only. Custom field saves on other CPTs (guests, etc.) do not trigger it.

How It Works

The action passes the episode ID, the show ID, and an array of the field IDs whose values changed in this save. Keep a map from the field IDs you care about to whatever keys your external system uses, skip the ones you don’t track, then read each changed value with benecaster_get_field() and push it.

Notes

The changed-field array contains only changed values. If the podcaster saves the episode editor without modifying any custom fields, this hook does not fire at all. If they change three fields, you get an array of three IDs. This makes it efficient to use without excessive external API calls.

Each benecaster_update_field() call is its own save. A podcaster’s editor save fires the hook once for all the fields it changed. Code that writes fields one at a time, such as an importer, fires it once per field. Clearing a stored value with null counts as a change.

Look up field definitions by ID. Use benecaster_get_field( $field_id, $episode_id ) to get the current stored value. If you need the field key or label, query FieldRegistry via the Benecaster container — field IDs are stable integers set at creation time.

benecaster_episode_meta_updated is the parallel hook for built-in meta. If you need to react to changes in Benecaster’s built-in episode fields (_benecaster_audio_url, _benecaster_episode_type, etc.), use benecaster_episode_meta_updated instead. Each hook covers its own domain — use both if you need both.

benecaster_field_value_saved fires per-field. If you prefer a lower-level callback that fires once per field value written (rather than once per save request), use benecaster_field_value_saved. The tradeoff: it fires for every CPT, so you must guard on the CPT slug it passes.

Related

Code

<?php
add_action( 'benecaster_episode_field_values_updated', function (
    int   $episode_id,
    int   $show_id,
    array $changed_field_ids
): void {
    foreach ( $changed_field_ids as $field_id ) {
        $value = benecaster_get_field( $field_id, $episode_id );
        my_addon_sync_field( $episode_id, $field_id, $value );
    }
}, 10, 3 );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →