black friday sale

Custom Fields
Re-Envisioned
Support General Registering meta boxes – limit frontend queries

  • Creator
    Topic
  • #21778
    wgstjf
    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #21806
    Long 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
    wgstjf
    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 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.