Registering meta boxes - limit frontend queries

Support General Registering meta boxes - limit frontend queries

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #21778
    wgstjfwgstjf
    Participant

    Hi guys,

    Quick question - using Query Monitor I can see that there are a large number of queries being run in the frontend of the site due to the registration of meta boxes (some of which do lookups on the database). Is there any downside to making the registration of them conditional on being in the admin area? Something like this...

    
    add_filter( 'rwmb_meta_boxes', 'indigo_register_metaboxes',999 );
    function indigo_register_metaboxes( $meta_boxes ) {
    
        if (is_admin()) {
            $meta_boxes[] = array(....);
            }
    }
    

    Cheers,

    Will

    #21806
    Long NguyenLong Nguyen
    Moderator

    Hi Will,

    Query, in simple meaning, is to fetch data from the database and show (or not) on the front end. Registering meta boxes, custom fields are not queries until you show the field's value by calling the helper function rwmb_meta() for example.

    Also, I will discuss with the developer team to take a look at queries of Meta Box and reduce any unnecessary queries. Thank you.

    #21810
    wgstjfwgstjf
    Participant

    Thanks Long,

    As previously mentioned, some of my meta boxes contain custom functions that require queries to run on the database. In the example below a custom function gets all users and formats them as required for a select_advanced metabox. As these metaboxes are only required in the admin area it would seem sensible for the filter rwmb_meta_boxes to only run if in admin area, unless there are downsides to this...

    
    // SELECT - Related User Account
     array(
        'name'    => __( 'Related User Account', 'indigo-metaboxes' ),
        'desc'    => __( 'Choose the user account related to this member', 'indigo-metaboxes' ),
        'id'      => 'member_user_id',
        'type'  => 'select_advanced',
        'options' => indigo_get_member_users(null,1),
        'placeholder'  => 'Choose user...',
        'columns'  => '3',
     ),
    

    Cheers,

    Will

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