Working with the field custom-html through filters

Support General Working with the field custom-html through filtersResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #27656
    MaxMax
    Participant

    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

    #27658
    MaxMax
    Participant
    #27673
    Long NguyenLong Nguyen
    Moderator

    Hi Max,

    Thank you for reaching out.

    1. 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.
    2. 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

    #27685
    MaxMax
    Participant

    OK. Thank you. This solved my problem.
    There remains a theoretical question. Do I have the ability to pass parameters to the callback function?

    #27704
    Long NguyenLong Nguyen
    Moderator

    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.

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