Custom Fields
Re-Envisioned
Support Meta Box Group Group and filter rwmb_field_ID_html issue

  • Creator
    Topic
  • #21244
    Resolved LucaBarbi
    Participant

    Hello! I’m using a clonable gruop to show a large data set on a custom post type admin page and the loading time is dramatically high. I’m trying to prevent the loading of the groups until user click on a button.

    To do that I find the filter rwmb_{field_id}_html and I write that piece of code for the called function:

    if (isset($_GET['show_products']) and !empty($_GET['show_products'])) {
       return $field_html;
     } elseif ($this->counter++ == 0) {
         return '<a>Mostra i prodotti</a>';
       } else {
          return null;
         }
    

    This solution is working fine, exept for the remove buttons that are seems to be ignored by the filter, so in my page, when the user didn’t clicked the button, I have zero group but over two hundreds remove buttons!

    How I can fix that problem? I would have something more elegant than hiding remove-clone on css because of the number of that.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #21250
    Long Nguyen
    Moderator

    Hi Luca,

    We have the extension MB Conditional Logic to show/hide meta boxes, custom fields, or any elements based on other fields’ values. For more information, please follow this documentation https://docs.metabox.io/extensions/meta-box-conditional-logic/.

    #21251
    LucaBarbi
    Participant

    Hi Long,

    I already tried with the solution you prospect, but the results is similar to set display: none in CSS and this solution doesn’t impact on load time.

    What I expect to find, is a solution that consent me to completely prevent loading the custom fields until user explicitly make a request for clicking the button (then I retrive the code by an Ajax call).

    My only problem whit this solution are the remove buttons, because even if the callable function for the filter rwmb_{field_id}_html return null value, the remove buttons are still on page.

    So, how can I prevent the load of the return buttons if the callable function return null?

    #21256
    LucaBarbi
    Participant

    Solved! The remove button is placed on the outer_html!

    #21258
    LucaBarbi
    Participant

    Sorry, I believed to find a solution, but didn’t work, so my question is still open!

    #21295
    Long Nguyen
    Moderator

    Hi,

    I think you can register the cloneable group field in a separate meta box, then use the filter rwmb_show_{$meta_box_id} to show/hide this meta box.

    add_filter( 'rwmb_show_{$meta_box_id}', function( $show, $meta_box ) {
        if ( true ) {
            return true;
        } else {
            return false;
        }
    }, 99, 2 );

    For more information, please follow this documentation https://docs.metabox.io/filters/#rwmb_show_meta_box_id.

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