Support Forum
Hello. viewed this topic
https://docs.metabox.io/using-custom-html-to-output-anything/. I understood how to work with the field through the return function. Is it possible to change the field through filters?
My task is this. I create a table with prices on the settings page. group + fields within the group I want the names of the lines that are in the first column to correspond to the page titles.
I will have 15 rows in my table.
I want to programmatically get the title of the page by the id of the page. Questions.
1) Can I in a function that is in PHP Callback
challenge different arguments? (I don't want to create 15 different PHP Callback functions)
2) Is there a filter that will change the field values?
tried like this:
field id = head_standart
add_filter( 'rwmb_field_meta', 'your_filter_function', 10, 3 );
function your_filter_function( $meta, $field, $saved ) {
if ( 'head_standart' == $field['id'] ) {
$meta = "<div>lll</div>";
}
return $meta;
}
not work
Hi Max,
Thank you for reaching out.
If you want to change the display of the field type custom_html
, please use the filter rwmb_{$field_id}_html
or rwmb_{$field_type}_html
because this field does not save the meta value in the database.
add_filter( 'rwmb_head_standart_html', 'your_filter_function', 10, 3 );
function your_filter_function( $field_html, $field, $meta ) {
if ( 'head_standart' == $field['id'] ) {
$field_html = '<div class="my-class">My Custom HTML</div>';
}
return $field_html;
}
Get more details on the documentation https://docs.metabox.io/filters/#rwmb_field_type_html
OK. Thank you. This solved my problem.
There remains a theoretical question. Do I have the ability to pass parameters to the callback function?
Hi Max,
There are no parameters to pass to the callback function. You can use the loop to show more custom HTML fields when registering the meta box.