Custom Fields
Support General Using rwmb_filter_id_value for cloned grouped sub fields

  • Creator
  • #27754
    Resolved BucketPress

    Hi I have the following group sub fields set up:
    - subfield_1
    - subfield_2
    - subfield_3

    The group can be cloned.

    Doing a test to see if this works by using the following code, but it doesn't seem to work:

    add_filter('rwmb_subfield_3_value', function($new, $field, $old) {
       return 'Test Value';
    }, 10, 3);

    Secondly, since the group can be cloned, if I am trying to set the value of subfield_3 based on the value of subfield_2, how can I target/get the value of each cloned group's subfield_2 and set the corresponding subfield_3 value in the above filter?

    If this were simple fields that cannot be cloned, then we could easily do something like:

    if ( isset($_POST['field_2']) ) { something to field_3 with field_2 value

    But how do we target subfields for a group that can be cloned?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
  • #27772
    Long Nguyen


    The group saves the group ID as meta key in the database so if you want to modify the subfield value, you need to use the filter of group ID. For example:

    add_filter( "rwmb_group_id_value", function( $new, $field, $old ) {
        $new['subfield_3'] = 'Test value';
        return $new;
    }, 99, 3 );

    Get more information about the group value here


    Hi Long Nguyen,

    Thanks, makes perfect sense to filter the parent Group_ID instead, and loop through the $new array to change the values of the cloned group and subfields.

    Have tried and it works.

    However, when I update a post, the 'changes' of values made through the filter does not show immediately. I have to refresh the post edit page again before the changes are shown.

    This makes the user think that changes have not been made upon clicking 'update' of post.

    Long Nguyen


    Yes, it the default behavior of Block editor when we use the PHP code to do something. The data was modified but it does not show until refreshing the page. You can try to use the Classic editor, after clicking update, the page also reloads.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.