Skip to main content

rwmb_after_save_field

This action runs after a field is saved.

do_action( 'rwmb_after_save_field', $null, $field, $new, $old, $object_id );

It accepts the following parameters:

NameDescription
$nullNot used
$fieldField settings
$newThe new (submitted) field value
$oldThe old field value
$object_idThe object ID

This action has variations:

  • rwmb_after_save_field: apply to all fields
  • rwmb_{$field_type}_after_save_field: apply to fields with a particular type
  • rwmb_{$field_id}_after_save_field: apply to a field with a particular id

Examples

Logging all values of a field using another custom field:

add_action( 'rwmb_event_date_after_save_field', function ( $null, $field, $new, $old, $object_id ) {
$log = get_post_meta( $object_id, 'log_event_dates', true );
$log[] = $new;
update_post_meta( $object_id, 'log_event_dates', $log );
}, 10, 5 );

Update another custom field based on a field value:

add_action( 'rwmb_event_date_after_save_field', function ( $null, $field, $new, $old, $object_id ) {
if ( $new < '2022-04-01' ) {
update_post_meta( $object_id, 'current_year', true );
}
}, 10, 5 );