Support Forum
Hello,
This filter is exactly what I need to manipulate the values of my registered fields before they've been saved to the DB. but apparently, it doesn't work, including all of its variations.
I've created a test environment with only the MetaBox plugin activated, put a breakpoint inside the filter, and also print something, but it doesn't go there.
here's my code:
add_filter( 'rwmb_meta_boxes', 'test_register_metabox' ); // register fields
add_filter( 'rwmb_text_value', 'test_save_field', 10, 5 ); // test a text field by field type
add_filter( 'rwmb_group_value', 'test_save_field', 10, 5 ); // test a group field by field type
add_filter( 'rwmb_test_simple_value', 'test_save_field', 10, 5 ); // test a text field by its id
add_filter( 'rwmb_test_group_value', 'test_save_field', 10, 5 ); // test a group field by its id
function test_save_field( $new, $field, $old, $object_id ) {
var_dump($new);
return $new;
}
function test_register_metabox( $meta_boxes ) {
$meta_boxes[] = array(
'id' => 'test',
'title' => 'Test Meta Box',
'post_types' => 'post',
'fields' => array(
array(
'id' => 'test_simple',
'name' => 'Test Simple Field',
'type' => 'text',
),
array(
'id' => 'test_group',
'type' => 'group',
'name' => 'Group Test',
'clone' => true,
'sort_clone' => true,
'fields' => array(
array(
'id' => 'test_1',
'type' => 'text',
'name' => 'Text Field',
),
array(
'id' => 'test_2',
'type' => 'wysiwyg',
'name' => 'HTML Field',
)
)
)
),
);
return $meta_boxes;
}
Am I doing something wrong?
I've also tried to search the filter inside the source code but didn't find anything. Is the filter even there?
Thanks!
Hi,
Here is the correct code
add_filter( 'rwmb_test_group_value', 'test_save_field', 10, 4 ); // test a group field by its id
function test_save_field( $new, $field, $old, $object_id ) {
var_dump($new);
die('12345'); //stop the code here
return $new;
}
Use one function for one field ID only.
Thanks, it's working 🙂