Filter: bricks/query/loop_object
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. While iterating through the query results, the iteration object could be manipulated using the bricks/query/loop_object like so:
add_filter( 'bricks/query/loop_object', function( $loop_object, $loop_key, $query_obj ) { if ( $query_obj->object_type !== 'my_query_type' ) { return $loop_object; }
// Perform some logic, for example: // global $post; // $post = get_post( $loop_object ); // setup_postdata( $post );
return $loop_object;}, 10, 3 );The filter callback receives two arguments:
$loop_objectis the current loop iteration value (from the results array)$loop_keyis the current loop iteration key (from the results array)$query_objis an instance of the\Bricks\Queryclass object
Related hooks:
- To add a query type to the Query control use
[bricks/setup/control_options](https://academy.bricksbuilder.io/article/filter-bricks-setup-control_options/) - To perform the custom query type and output the results use
[bricks/query/run](https://academy.bricksbuilder.io/article/filter-bricks-query-run/)
Was this page helpful?