rwmb-field-meta filter for cloneable groups

Support General rwmb-field-meta filter for cloneable groupsResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #44888
    Nicholas CoxNicholas Cox
    Participant

    Hi

    I'm trying to edit the serialized value before the form loads but the filter for rwmb-field-meta does not allow me to target this?

    is it possible to edit the value of a cloneable group field before the form loads?

    thanks

    Nick

    #44898
    PeterPeter
    Moderator

    Hello Nick,

    It is possible to adjust the field value before displaying it in the editing form. You can use the filter hook rwmb_{$field_id}_field_meta to hook the callback function to a specific field.

    The subfield in a cloneable group will have a structure like this

    Array
    (
        [0] => Array
            (
                [text_field_id] => test text 1
            )
    
        [1] => Array
            (
                [text_field_id] => test text 2
            )
    
    )

    then you can change the text field value in the group with the code:

    add_filter( 'rwmb_groupFieldID_field_meta', function( $value, $field, $saved ) {
    	$value[1]['text_field_id'] = 'adjust the second text field value';
    	return $value;
    }, 10, 3);

    Following the documentation https://docs.metabox.io/filters/rwmb-field-meta/

    #44909
    Nicholas CoxNicholas Cox
    Participant

    Hi

    thanks, i tested this and i recieve the following error.

    Fatal error: Uncaught TypeError: RWMB_Clone::html(): Argument #1 ($meta) must be of type array, null given. meta-box\meta-box\inc\clone.php on line 6

    TypeError: RWMB_Clone::html(): Argument #1 ($meta) must be of type array, null given, called in meta-box\meta-box\inc\clone.php on line 6

    my code:

    add_filter( 'rwmb_basket_items_field_meta', [ $this, 'dctest' ], 10, 3);
    
    public function dctest( $value, $field, $saved ) {	
         // error_log(print_r($value, true));
    }
    #44910
    Nicholas CoxNicholas Cox
    Participant

    ignore my last message, i was missing the return value in the function

    #44913
    PeterPeter
    Moderator

    Hello,

    Does it work on your site?

    #44916
    Nicholas CoxNicholas Cox
    Participant

    hi yes it works just fine thanks

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