Filter "rwmb_{$field_type}_value" doesn't work
- This topic has 2 replies, 2 voices, and was last updated 3 years, 4 months ago by
Aharon.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
February 15, 2022 at 4:44 PM #33908
Aharon
ParticipantHello,
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!
February 15, 2022 at 11:05 PM #33921Long Nguyen
ModeratorHi,
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.
February 16, 2022 at 5:05 PM #33936Aharon
ParticipantThanks, it's working 🙂
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.