Working with the field custom-html through filters
- This topic has 4 replies, 2 voices, and was last updated 4 years ago by
Long Nguyen.
-
AuthorPosts
-
April 26, 2021 at 5:59 PM #27656
Max
ParticipantHello. 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_standartadd_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
April 26, 2021 at 6:03 PM #27658Max
ParticipantApril 27, 2021 at 6:35 AM #27673Long Nguyen
ModeratorHi Max,
Thank you for reaching out.
- As I understand, you want to create a table that shows the list of posts and some information (price, label ...) on the settings page. I think you can use a loop to show it without using 15 callback functions.
-
If you want to change the display of the field type
custom_html
, please use the filterrwmb_{$field_id}_html
orrwmb_{$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
April 27, 2021 at 1:16 PM #27685Max
ParticipantOK. Thank you. This solved my problem.
There remains a theoretical question. Do I have the ability to pass parameters to the callback function?April 27, 2021 at 7:11 PM #27704Long Nguyen
ModeratorHi 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.
-
AuthorPosts
- You must be logged in to reply to this topic.