{"id":2327,"date":"2022-03-30T10:20:59","date_gmt":"2022-03-30T10:20:59","guid":{"rendered":"https:\/\/academy.bricksbuilder.io\/?post_type=bricks_article&p=2327"},"modified":"2022-03-30T10:26:25","modified_gmt":"2022-03-30T10:26:25","slug":"filter-bricks-query-run","status":"publish","type":"bricks_article","link":"https:\/\/academy.bricksbuilder.io\/article\/filter-bricks-query-run\/","title":{"rendered":"Filter: bricks\/query\/run"},"content":{"rendered":"\n
The Bricks Query Loop<\/a> supports 3 types of queries by default (Posts, Terms and Users). But it can be extended to support any other query. To return a custom query result, Bricks can be extended using the WP filter The filter callback receives two arguments: <\/p>\n\n\n\n Note: This hook should be used to add different types of query results. If you want to alter the posts, terms, or users query, use the following hooks:<\/p>\n\n\n\n Related hooks:<\/p>\n\n\n\n The Bricks Query Loop supports 3 types of queries by default (Posts, Terms and Users). But it can be extended to support any other query. To return a custom query result, Bricks can be extended using the WP filter bricks\/query\/run like so: The filter callback receives two arguments: $results is the results array (empty by […]<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":92,"template":"","format":"standard","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2327"}],"collection":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article"}],"about":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/types\/bricks_article"}],"author":[{"embeddable":true,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/users\/1"}],"version-history":[{"count":6,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2327\/revisions"}],"predecessor-version":[{"id":2435,"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/bricks_article\/2327\/revisions\/2435"}],"wp:attachment":[{"href":"https:\/\/academy.bricksbuilder.io\/api\/wp\/v2\/media?parent=2327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}bricks\/query\/run<\/code> like so:<\/p>\n\n\n\n
add_filter( 'bricks\/query\/run', function( $results, $query_obj ) {\n if ( $query_obj->object_type !== 'my_query_type' ) {\n\treturn $results;\n }\n\n \/\/ Perform the query\n \/\/ Assign the results to $results (array)\n \n return $results;\n}, 10, 2 );<\/code><\/pre>\n\n\n\n
$results<\/code> is the results array (empty by default). The loop will iterate through this array.<\/li>
$query_obj<\/code> is an instance of the
\\Bricks\\Query<\/code> class object<\/li><\/ul>\n\n\n\n
bricks\/posts\/query_vars<\/a><\/code><\/li>
bricks\/setup\/control_options<\/a><\/code><\/li>
bricks\/query\/loop_object<\/a><\/code><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"