🚀 🚀 LAUNCH SALE - 33% off all Lifetime Licenses

Hooks Reference

Last Modified: February 16, 2026

GB Query Enhancements includes a number of useful hooks to allow developers to extend and alter the plugin’s functionality.

Hooks Reference

This document lists all custom WordPress hooks (filters) provided by GB Query Enhancements. These hooks allow developers to customize query behavior, modify responses, and extend functionality.

Term Query Hooks

gb_query_enhancements_max_terms

Filter the maximum number of terms returned when “Show All” (-1 or 0) is selected for posts per page. This prevents performance issues from unbounded queries.

Parameters:

ParameterTypeDescription
$max_termsintMaximum terms limit. Default: 150

Example:

add_filter( 'gb_query_enhancements_max_terms', function( $max_terms ) {
    return 300; // Allow up to 300 terms
} );

gb_query_enhancements_term_query_args

Filter the final term query arguments before the query is executed. This is the main hook for modifying term queries and runs for both frontend rendering and editor previews.

Parameters:

ParameterTypeDescription
$normalizedarrayThe sanitized/normalized query arguments
$argsarrayThe original unsanitized arguments
$attributesarrayThe block attributes
$pageintThe current page number

Example:

add_filter( 'gb_query_enhancements_term_query_args', function( $normalized, $args, $attributes, $page ) {
    // Only show terms with posts
    $normalized['hide_empty'] = true;

    // Add custom ordering based on block attribute
    if ( ! empty( $attributes['customOrder'] ) ) {
        $normalized['orderby'] = $attributes['customOrder'];
    }

    return $normalized;
}, 10, 4 );

gb_query_enhancements_term_query_data

Filter the full term query data array after the query has executed. Use this to modify results (reorder, remove, inject synthetic items), override pagination values, or add custom data.

Parameters:

ParameterTypeDescription
$query_dataarrayThe query data array with keys: data (array of terms), no_results (bool), args (array), total (int), max_num_pages (int)
$attributesarrayThe block attributes
$pageintThe current page number

Example:

add_filter( 'gb_query_enhancements_term_query_data', function( $query_data, $attributes, $page ) {
    // Remove terms that only have posts in draft status
    $query_data['data'] = array_filter( $query_data['data'], function( $term ) {
        $posts = get_posts( [
            'post_status' => 'publish',
            'tax_query'   => [ [ 'taxonomy' => $term->taxonomy, 'terms' => $term->term_id ] ],
            'fields'      => 'ids',
            'numberposts' => 1,
        ] );
        return ! empty( $posts );
    } );

    $query_data['total']      = count( $query_data['data'] );
    $query_data['no_results'] = empty( $query_data['data'] );

    return $query_data;
}, 10, 3 );

gb_query_enhancements_rest_term_query_args

Filter term query arguments specifically for REST API requests (editor previews). Runs after gb_query_enhancements_term_query_args.

Parameters:

ParameterTypeDescription
$normalized_argsarrayThe normalized term query arguments
$request\WP_REST_RequestThe REST request object
$argsarrayThe original args passed to the request
$attributesarrayThe attributes passed to the request

Example:

add_filter( 'gb_query_enhancements_rest_term_query_args', function( $args, $request, $original_args, $attributes ) {
    // Limit preview results in editor
    $args['number'] = min( $args['number'] ?? 10, 20 );
    return $args;
}, 10, 4 );

gb_query_enhancements_rest_terms_response

Filter the REST API response for term queries. Useful for adding custom data to the editor preview.

Parameters:

ParameterTypeDescription
$responsearrayThe response data containing terms, total, total_pages, page
$request\WP_REST_RequestThe REST request object
$termsarrayThe raw terms array

Example:

add_filter( 'gb_query_enhancements_rest_terms_response', function( $response, $request, $terms ) {
    // Add taxonomy info to response
    $response['taxonomy_info'] = get_taxonomy( $request->get_param( 'taxonomy' ) );
    return $response;
}, 10, 3 );

gb_query_enhancements_term_response_data

Filter individual term data in REST API responses. Called for each term when formatting the response.

Parameters:

ParameterTypeDescription
$term_dataarrayThe term data array with keys: term_id, name, slug, taxonomy, description, parent, count
$term\WP_TermThe term object

Example:

add_filter( 'gb_query_enhancements_term_response_data', function( $term_data, $term ) {
    // Add term meta to response
    $term_data['featured_image'] = get_term_meta( $term->term_id, 'featured_image', true );
    $term_data['custom_url'] = get_term_meta( $term->term_id, 'custom_url', true );
    return $term_data;
}, 10, 2 );

gb_query_enhancements_term_meta_query

Filter the built meta_query array for term queries. Useful for adding complex meta conditions.

Parameters:

ParameterTypeDescription
$meta_queryarrayThe built meta query array
$meta_paramsarrayThe original meta parameters

Example:

add_filter( 'gb_query_enhancements_term_meta_query', function( $meta_query, $meta_params ) {
    // Add additional meta clause
    $meta_query[] = [
        'key'     => 'is_featured',
        'value'   => '1',
        'compare' => '='
    ];
    return $meta_query;
}, 10, 2 );

gb_query_enhancements_term_loop_item_context

Filter the block context array for each term loop item before the inner block is rendered. Use this to inject additional context values (e.g., precomputed data, ACF fields, related post IDs) into loop items.

Parameters:

ParameterTypeDescription
$contextarrayThe block context array with keys: taxonomy, termId, postId, generateblocks/queryType, generateblocks/loopIndex, generateblocks/loopItem
$item\WP_TermThe term object for the current loop item
$argsarrayThe query args
$block\WP_BlockThe parent block instance
$indexintThe current loop index (1-based)

Example:

add_filter( 'gb_query_enhancements_term_loop_item_context', function( $context, $item, $args, $block, $index ) {
    // Attach a custom "featured image" attachment ID to each term's context
    $context['termFeaturedImage'] = get_term_meta( $item->term_id, 'featured_image', true );

    return $context;
}, 10, 5 );

gb_query_enhancements_term_query_render_loop_items

Filter the rendered HTML content for term query loop items. Called after all items are rendered.

Parameters:

ParameterTypeDescription
$contentstringThe rendered HTML content
$itemsarrayThe term items that were rendered
$block\WP_BlockThe block instance

Example:

add_filter( 'gb_query_enhancements_term_query_render_loop_items', function( $content, $items, $block ) {
    // Wrap content in custom container
    if ( ! empty( $items ) ) {
        $content = '<div class="terms-grid">' . $content . '</div>';
    }
    return $content;
}, 10, 3 );

User Query Hooks

gb_query_enhancements_max_users

Filter the maximum number of users returned when “Show All” (-1 or 0) is selected for posts per page.

Parameters:

ParameterTypeDescription
$max_usersintMaximum users limit. Default: 150

Example:

add_filter( 'gb_query_enhancements_max_users', function( $max_users ) {
    return 50; // Limit to 50 users for performance
} );

gb_query_enhancements_user_query_args

Filter the final user query arguments before the query is executed.

Parameters:

ParameterTypeDescription
$normalizedarrayThe sanitized/normalized query arguments
$argsarrayThe original unsanitized arguments
$attributesarrayThe block attributes
$pageintThe current page number

Example:

add_filter( 'gb_query_enhancements_user_query_args', function( $normalized, $args, $attributes, $page ) {
    // Only show users who have published posts
    $normalized['has_published_posts'] = true;

    // Exclude specific users
    $normalized['exclude'] = [ 1 ]; // Exclude admin

    return $normalized;
}, 10, 4 );

gb_query_enhancements_user_query_data

Filter the full user query data array after the query has executed. Use this to modify results (reorder, remove, inject synthetic items), override pagination values, or add custom data.

Parameters:

ParameterTypeDescription
$query_dataarrayThe query data array with keys: data (array of user objects), no_results (bool), args (array), total (int), max_num_pages (int)
$attributesarrayThe block attributes
$pageintThe current page number

Example:

add_filter( 'gb_query_enhancements_user_query_data', function( $query_data, $attributes, $page ) {
    // Sort users by custom priority meta
    usort( $query_data['data'], function( $a, $b ) {
        $priority_a = get_user_meta( $a->ID, 'display_priority', true ) ?: 99;
        $priority_b = get_user_meta( $b->ID, 'display_priority', true ) ?: 99;
        return $priority_a - $priority_b;
    } );

    return $query_data;
}, 10, 3 );

gb_query_enhancements_rest_user_query_args

Filter user query arguments specifically for REST API requests (editor previews).

Parameters:

ParameterTypeDescription
$normalized_argsarrayThe normalized user query arguments
$request\WP_REST_RequestThe REST request object
$argsarrayThe original args passed to the request
$attributesarrayThe attributes passed to the request

Example:

add_filter( 'gb_query_enhancements_rest_user_query_args', function( $args, $request, $original_args, $attributes ) {
    // Limit to specific roles in editor preview
    if ( empty( $args['role'] ) ) {
        $args['role__in'] = [ 'author', 'editor', 'administrator' ];
    }
    return $args;
}, 10, 4 );

gb_query_enhancements_rest_users_response

Filter the REST API response for user queries.

Parameters:

ParameterTypeDescription
$responsearrayThe response data containing users, total, total_pages, page
$request\WP_REST_RequestThe REST request object
$usersarrayThe raw users array

Example:

add_filter( 'gb_query_enhancements_rest_users_response', function( $response, $request, $users ) {
    // Add available roles to response
    $response['available_roles'] = wp_roles()->get_names();
    return $response;
}, 10, 3 );

gb_query_enhancements_user_response_data

Filter individual user data in REST API responses.

Parameters:

ParameterTypeDescription
$user_dataarrayThe user data array with keys: ID, user_login, user_nicename, user_email, user_url, user_registered, display_name
$user\WP_UserThe user object

Example:

add_filter( 'gb_query_enhancements_user_response_data', function( $user_data, $user ) {
    // Add user meta
    $user_data['bio'] = get_user_meta( $user->ID, 'description', true );
    $user_data['avatar_url'] = get_avatar_url( $user->ID );
    $user_data['post_count'] = count_user_posts( $user->ID );
    return $user_data;
}, 10, 2 );

gb_query_enhancements_user_meta_query

Filter the built meta_query array for user queries.

Parameters:

ParameterTypeDescription
$meta_queryarrayThe built meta query array
$meta_paramsarrayThe original meta parameters

Example:

add_filter( 'gb_query_enhancements_user_meta_query', function( $meta_query, $meta_params ) {
    // Only show verified users
    $meta_query[] = [
        'key'     => 'verified',
        'value'   => '1',
        'compare' => '='
    ];
    return $meta_query;
}, 10, 2 );

gb_query_enhancements_user_loop_item_context

Filter the block context array for each user loop item before the inner block is rendered. Use this to inject additional context values into loop items.

Parameters:

ParameterTypeDescription
$contextarrayThe block context array with keys: userId, postId, generateblocks/queryType, generateblocks/loopIndex, generateblocks/loopItem
$itemstdClassThe user data object for the current loop item
$argsarrayThe query args
$block\WP_BlockThe parent block instance
$indexintThe current loop index (1-based)

Example:

add_filter( 'gb_query_enhancements_user_loop_item_context', function( $context, $item, $args, $block, $index ) {
    // Add the user's latest post ID to context
    $latest = get_posts( [
        'author'      => $item->ID,
        'numberposts' => 1,
        'fields'      => 'ids',
    ] );

    $context['userLatestPostId'] = $latest[0] ?? 0;

    return $context;
}, 10, 5 );

gb_query_enhancements_user_query_render_loop_items

Filter the rendered HTML content for user query loop items.

Parameters:

ParameterTypeDescription
$contentstringThe rendered HTML content
$itemsarrayThe user items that were rendered
$block\WP_BlockThe block instance

Example:

add_filter( 'gb_query_enhancements_user_query_render_loop_items', function( $content, $items, $block ) {
    // Add schema markup wrapper
    if ( ! empty( $items ) ) {
        $content = '<div itemscope itemtype="https://schema.org/ItemList">' . $content . '</div>';
    }
    return $content;
}, 10, 3 );

Dynamic Tags Hooks

gb_query_enhancements_dynamic_tag_output_{$tag}

Filter the output of a specific dynamic tag. The dynamic portion of the hook name, $tag, refers to the tag name.

Available tags: term_title, term_description, term_archive_url, term_count, user_display_name, user_email, user_bio, user_avatar_url, user_url, user_posts_url, user_post_count

Parameters:

ParameterTypeDescription
$outputstringThe dynamic tag output
$optionsarrayThe dynamic tag options
$instance\WP_BlockThe block instance containing the tag

Examples:

// Truncate long term descriptions to 100 characters
add_filter( 'gb_query_enhancements_dynamic_tag_output_term_description', function( $output, $options, $instance ) {
    if ( strlen( $output ) > 100 ) {
        $output = mb_substr( $output, 0, 100 ) . '&hellip;';
    }
    return $output;
}, 10, 3 );

// Output user email as a mailto link
add_filter( 'gb_query_enhancements_dynamic_tag_output_user_email', function( $output, $options, $instance ) {
    if ( ! empty( $output ) && is_email( $output ) ) {
        $output = sprintf( '<a href="mailto:%s">%s</a>', esc_attr( $output ), esc_html( $output ) );
    }
    return $output;
}, 10, 3 );

// Append a role badge after user display name
add_filter( 'gb_query_enhancements_dynamic_tag_output_user_display_name', function( $output, $options, $instance ) {
    $loop_item = $instance->context['generateblocks/loopItem'] ?? null;
    $roles     = is_object( $loop_item ) && isset( $loop_item->roles ) ? $loop_item->roles : [];

    if ( in_array( 'administrator', $roles, true ) ) {
        $output .= ' <span class="role-badge role-admin">Admin</span>';
    }

    return $output;
}, 10, 3 );

gb_query_enhancements_supported_core_blocks

Filter the list of core blocks that receive dynamic tag replacements and loop context injection. This filters the saved setting value from the Settings > GB Query Enhancements > Core Block Support page. The default is an empty array — no core blocks are enabled until explicitly checked in settings.

Parameters:

ParameterTypeDescription
$blocksarrayArray of core block names saved in settings (default: [])

Example:

// Programmatically enable core/paragraph regardless of the saved setting
add_filter( 'gb_query_enhancements_supported_core_blocks', function( $blocks ) {
    if ( ! in_array( 'core/paragraph', $blocks, true ) ) {
        $blocks[] = 'core/paragraph';
    }
    return $blocks;
} );

gb_query_enhancements_context_keys

Filter the context keys passed through from parent blocks to supported core blocks during rendering. This is the companion to gb_query_enhancements_supported_core_blocks — if you add custom context via the loop item context filters, you’ll need to add the corresponding keys here for them to be available in core blocks.

Parameters:

ParameterTypeDescription
$keysarrayArray of context key strings

Example:

add_filter( 'gb_query_enhancements_context_keys', function( $keys ) {
    // Pass custom context keys through to core blocks
    $keys[] = 'termFeaturedImage';
    $keys[] = 'userLatestPostId';
    return $keys;
} );

Hook Execution Order

Understanding when hooks fire helps you choose the right one:

Frontend Rendering

  1. gb_query_enhancements_term_query_args / gb_query_enhancements_user_query_args
  2. gb_query_enhancements_term_meta_query / gb_query_enhancements_user_meta_query (if meta query used)
  3. gb_query_enhancements_term_query_data / gb_query_enhancements_user_query_data
  4. gb_query_enhancements_supported_core_blocks / gb_query_enhancements_context_keys (during block rendering)
  5. gb_query_enhancements_term_loop_item_context / gb_query_enhancements_user_loop_item_context (per item)
  6. gb_query_enhancements_dynamic_tag_output_{$tag} (per dynamic tag)
  7. gb_query_enhancements_term_query_render_loop_items / gb_query_enhancements_user_query_render_loop_items

Editor Preview (REST API)

  1. gb_query_enhancements_term_query_args / gb_query_enhancements_user_query_args
  2. gb_query_enhancements_rest_term_query_args / gb_query_enhancements_rest_user_query_args
  3. gb_query_enhancements_term_response_data / gb_query_enhancements_user_response_data (per item)
  4. gb_query_enhancements_rest_terms_response / gb_query_enhancements_rest_users_response