Processwire add new field to repeater matrix
<?php
/**
* Add Field To Repeater Matrix
*
*/
// Name of repeater matrix field
$matrix_field_name = 'test_matrix';
// Name of matrix type you want to add field to
$matrix_type_name = 'type_1';
// Name of field you want to add to matrix type
$add_field_name = 'images';
// Get field objects
$matrix_field = $fields->get($matrix_field_name);
$add_field = $fields->get($add_field_name);
// Add field to repeater matrix fieldgroup
$matrix_template = $templates->get("repeater_$matrix_field_name");
$matrix_fieldgroup = $matrix_template->fieldgroup;
$matrix_fieldgroup->add($add_field);
$matrix_fieldgroup->save();
// Associate field with matrix type
$matrix_types = $matrix_field->type->getMatrixTypes($matrix_field);
$matrix_type_integer = $matrix_types[$matrix_type_name];
$property = "matrix{$matrix_type_integer}_fields";
$field_ids_in_type = $matrix_field->$property;
$field_ids_in_type[] = $add_field->id;
$matrix_field->$property = $field_ids_in_type;
$matrix_field->save();
/**
* Search for page by repeater matrix field
*
*/
$get_pages = $pages->find("REAPEATR_MATRIX_NAME.FIELD_NAME=FIELD_VALUE");
// or
$get_pages = $pages->find("title|REAPEATR_MATRIX_NAME.FIELD_NAME~=$q");