Hi,
Yes, it is possible. We can create a new field type, extends the class RWMB_Key_Value_Field which render the field key_value
and change the default input type=text for value field to textarea.
– Create a new field type custom_key_value
:
if ( class_exists( 'RWMB_Field' ) ) {
class RWMB_Custom_Key_Value_Field extends RWMB_Key_Value_Field {
public static function html( $meta, $field ) {
// Key.
$key = isset( $meta[0] ) ? $meta[0] : '';
$attributes = self::get_attributes( $field, $key );
$attributes['placeholder'] = $field['placeholder']['key'];
$html = sprintf( '<input %s>', self::render_attributes( $attributes ) );
// Value.
$val = isset( $meta[1] ) ? $meta[1] : '';
$attributes = self::get_attributes( $field, $val );
$attributes['placeholder'] = $field['placeholder']['value'];
$html .= sprintf( '<textarea %s>' . $attributes['value'] . '</textarea>', self::render_attributes( $attributes ) );
return $html;
}
}
}
– Use the new field type:
add_filter( 'rwmb_meta_boxes', 'custom_key_value_field' );
function custom_key_value_field( $meta_boxes ){
$meta_boxes[] = array(
'title' => 'Custom Key Value Meta Box',
'post_type' => 'post',
'id' => 'custom_key_value_meta_box',
'fields' => array(
array(
'name' => 'Custom Key Value Field',
'id' => 'custom_key_value_field',
'type' => 'custom_key_value',
)
),
);
return $meta_boxes;
}
For more information, please follow the documentation:
https://docs.metabox.io/custom-field-type/
https://github.com/wpmetabox/meta-box/blob/master/inc/fields/key-value.php