Hi,
I think normalize filter or field_meta filter both works. However, using normalize filter seems to be better.
But why don't you just use a condition check when defined meta boxes? I think it's faster. Something like this:
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
$field = array(
'id' => 'test',
'type' => 'text',
'std' => 'Default value',
);
if ( is_admin() ) {
$post_id = isset( $_GET['post'] ) ? $_GET['post'] : ( isset( $_POST['post_ID'] ) ? $_POST['post_ID'] : false );
if ( 1 == $post_id ) {
$field['std'] = 'Another default value';
}
}
$meta_boxes[] = array(
// ...
'fields' => array(
$field,
// ...
),
);
return $meta_boxes;
} );
Or you can filter directly to rwmb_meta_boxes
to change the std
value of a field:
add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
if ( is_admin() ) {
$post_id = isset( $_GET['post'] ) ? $_GET['post'] : ( isset( $_POST['post_ID'] ) ? $_POST['post_ID'] : false );
if ( 1 == $post_id ) {
$meta_boxes['fields'][0]['std'] = 'Another default value'; // First field
}
}
return $meta_boxes;
}, 9999 ); // High priority to make sure this function run last