Skip to main content

benecaster_register_field_cpt()

Registers a custom post type with the Benecaster field system, making it available as an “Attached to” option in the Field Group editor.

Signature

benecaster_register_field_cpt( string $cpt_slug, string $label ): void

Parameters

Name Type Description
$cpt_slug string The registered CPT slug — e.g. 'benecaster_guest'
$label string Human-readable label shown in the Field Group editor dropdown — e.g. 'Guest'

Return Value

void

When to Call

Call inside a benecaster_boot callback, or during plugins_loaded after Benecaster is loaded. The field registry is not available before the plugin boots.

Core automatically registers benecaster_episode as 'Episode'. Add-ons register their own CPTs.

Notes

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

If the same $cpt_slug is registered more than once, the later label overwrites the previous one. This is intentional — it lets a parent plugin set a default label that an add-on can override.

After registration, podcasters can create Field Groups attached to the CPT in Benecaster → Fields. The REST endpoint GET /field-values/{cpt}/{object_id} accepts read and write requests for any registered CPT slug. The benecaster_field_groups filter fires with $cpt_slug set to the registered value, so programmatic group injection works the same way it does for episodes.

Example Usage

Register the Guest Manager CPT so field groups can be attached to guest records:

add_action( 'benecaster_boot', function( \Benecaster\Container $container ): void {
    benecaster_register_field_cpt(
        'benecaster_guest',
        __( 'Guest', 'benecaster-guest-manager' )
    );
} );

After registration, the Field Group editor shows “Guest” in the “Attached to” dropdown. Podcasters can create field groups for guest records. The guest editor can load and save values using the same REST endpoints as the episode editor:

// In your React component (using the same hooks as the episode editor):
import { useFieldValues, useSaveFieldValues } from '../hooks/useFieldValues';

function GuestEditor({ guestId }) {
    const { data, isLoading } = useFieldValues( 'benecaster_guest', guestId );
    const saveMutation        = useSaveFieldValues();

    // data.groups is the same FieldGroupWithValues[] shape the episode editor receives.
}