bricks_create_global_query
Overview
Create a reusable global query configuration that can be referenced by any element with a query loop across the entire site. Global queries (Bricks v2.1) centralize query settings so you define them once and reuse everywhere.
Supports all four object types: post (WP_Query), term (WP_Term_Query), user (WP_User_Query), and api (external REST API). After creation, any element can reference this query via useGlobalQuery: "<id>" in its query settings. Updating the global query automatically propagates to all referencing elements.
Key Features
When to Use
Setting up complex queries with tax_query + meta_query that would be tedious to configure on each element
Establishing consistent query configurations across the site
Building a library of reusable queries for a multi-template site
The queried post type or taxonomy must exist
For API queries: a valid, accessible API endpoint
When NOT to Use
You need to list existing global queries — use bricks_get_global_queries first
The query needs to be different on each page (e.g., per-page category filtering)
Parameters
labelstringREQUIREDcategorystringoptionalquery.objectTypestringoptionalpost Values: post, term, user, apiquery.post_typestring | string[]optionalquery.posts_per_pagenumberoptionalquery.orderbystringoptionalquery.orderstringoptionalASC, DESCquery.tax_queryarrayoptionalquery.meta_queryarrayoptionalquery.taxonomystring | string[]optionalquery.rolestring | string[]optionalquery.api_urlstringoptionalCode Examples
Warning: Undefined array key "example_output" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 12
Create and reference a global blog query
Create a reusable "Latest Blog Posts" query and reference it from a query loop element.
// Step 1: Create the global query
const result = await bricks_create_global_query({
label: "Latest Blog Posts",
category: "Blog",
query: {
objectType: "post",
post_type: "post",
posts_per_page: 6,
orderby: "date",
order: "DESC",
exclude_current_post: true
}
});
// Returns: { id: "gq_abc123", label: "Latest Blog Posts", ... }
// Step 2: Reference it in any query loop
bricks_set_query_loop({
page_id: 33,
element_id: "loop-item-id",
query: { useGlobalQuery: "gq_abc123" }
});Common Mistakes
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Warning: Undefined array key "fix_description" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 47
Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-includes/kses.php on line 2018
Warning: Undefined array key "wrong_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 48
Warning: Undefined array key "right_code" in /var/www/vhosts/mcpbricksbuilder.wecode.swiss/httpdocs/wp-content/themes/bricks/includes/elements/code.php(236) : eval()'d code on line 49
Tips & Warnings
Use descriptive labels like « Latest 6 Blog Posts » or « Featured Products (In Stock) » so the query purpose is clear when browsing the global queries list.
Organize with categories on sites with many global queries. Common categories: « Blog », « Products », « Team », « Portfolio ».
Update propagation: When you update a global query with bricks_update_global_query, all elements referencing it automatically use the new settings on the next page load.