Skip to main content

benecaster_update_field()

Utilities Free
benecaster_update_field( int $field_id, int $object_id, mixed $value ): void

Writes one custom field value onto one object. It is the setter half of benecaster_get_field(), and it writes through the same store as the episode editor, so everything listening for a field change hears an import or an add-on exactly as it hears a podcaster.

What it checks, and what it does not. It checks that the field’s group is attached to the object’s post type, which is what the editor’s own save checks. It does not check the value: a number in a text field is stored as you sent it.

The hooks. benecaster_field_value_saved fires for the write. On an episode whose value changed, benecaster_episode_field_values_updated fires as well. Each call is its own save, so writing several fields in a loop fires that hook once per field.

Addressed by ID. Like the getter, it takes the numeric field ID rather than a name. IDs differ between installs, so read the ID from the Field Group editor and keep it in one constant or setting rather than scattering the number through your code.

See Custom Fields for the podcaster-facing side of field groups.

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). Same addressing as benecaster_get_field().
$object_id int Yes The post ID of the object to write the value to.
$value mixed Yes The value to store. Arrays and objects are stored as JSON. Pass null to delete the stored value.

Return Value

Type: void

Nothing. There is no success flag: an unknown field ID, or an object whose post type is not the one the field's group is attached to, writes nothing and raises _doing_it_wrong().

Example

benecaster_update_field( 12, $episode_id, 'Acme Mattresses' );

// Clear it again.
benecaster_update_field( 12, $episode_id, null );

Hooks Fired

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