This Pro tutorial provides the steps to create a custom query type for outputting the values of one or more instances/items/rows of a cloneable custom field created using Meta Box in Bricks.
This is similar to our earlier Looping Through a Cloneable Meta Box Sub Field in Bricks tutorial.
Note 1: Bricks has built-in support for a Meta Box group. But there could be certain times when you don’t want to use a group-type field and hence this tutorial.
Note 2: It is probably easier/simpler/faster to just use a Code Block and output the values of your cloneable field using the code that Meta Box generates than implementing this tutorial.

If you want to use Bricks elements like Basic Text for the output for visual styling though, follow along.
We shall also ensure that the parent Section gets output only if there is at least one item of the cloneable field.
Let’s take an example of a Course CPT that has a cloneable “Course Date” Date Picker field.

and for a particular course, the field is populated like this:

Step 1
Add the following in child theme‘s functions.php or a code snippets plugin:
// Add a new "Course Dates" query type.
add_filter( 'bricks/setup/control_options', function( $control_options ) {
// new option in the dropdown
$control_options['queryTypes']['bl_course_dates'] = esc_html__( 'Course Dates' );
return $control_options;
} );
// Run new query if option is selected.
add_filter( 'bricks/query/run', function( $results, $query_obj ) {
if ( $query_obj->object_type !== 'bl_course_dates' ) {
return $results;
}
// if option is selected, run the specified query function
if ( $query_obj->object_type === 'bl_course_dates' ) {
$results = bl_run_new_query_20230415();
}
return $results;
}, 10, 2 );
/* Return a custom array */
function bl_run_new_query_20230415() {
// avoid Undefined Function Error when Meta Box is not active.
if ( ! function_exists( 'rwmb_meta' ) ) {
function rwmb_meta( $key, $args = '', $post_id = null ) {
return false;
}
}
return rwmb_meta( 'course_date' ) ?? [];
}
// Function to get the looping object.
function bl_get_looping_object() {
return BricksQuery::get_loop_object();
}
// Function to get the count of the new query.
function get_count_new_query_20230415() {
return count( bl_run_new_query_20230415() );
}
Customize as needed by modifying the field ID etc.
Step 2
Set up a query loop in your single post Bricks template.
Change the type of query to “Course Dates” or if you have changed it in the above code, to that.
Add a Basic Text element inside your query loop element and change its text to:
{echo:bl_get_looping_object}
This outputs the value of each item in your cloneable field.
Step 3
Apply a Dynamic data condition on the Section.

{echo:get_count_new_query_20230415}