You could set up a custom query like this:
add_filter( 'bricks/setup/control_options', function( $control_options ) {
$control_options['queryTypes']['my_query_type'] = esc_html__( 'My Query Type', 'my-plugin' );
return $control_options;
} );
add_filter( 'bricks/query/run', function( $results, $query_obj ) {
if ( $query_obj->object_type !== 'my_query_type' ) {
return $results;
}
return [
[
'name' => 'Bob',
'phone' => '1234567'
],
[
'name' => 'Peter',
'phone' => '7654321'
],
];
}, 10, 2 );
add_filter( 'bricks/query/loop_object', function( $loop_object, $loop_key, $query_obj ) {
if ( $query_obj->object_type !== 'my_query_type' ) {
return $loop_object;
}
/* Usually you'd prepare a WP_Post object or something
* in here (see official documentation).
* In this specific case there is nothing to do here.
*/
return $loop_object;
}, 10, 3 );
To access the values in Bricks you can use the echo
tag with a small helper function like this:
function get_custom_loop_object_property( $name ) {
$loop_object = \Bricks\Query::get_loop_object();
if ( ! $loop_object ) return false;
if ( ! is_array( $loop_object ) ) return false;
if ( ! array_key_exists( $name, $loop_object ) ) return false;
return $loop_object[$name];
}
Then you can call it within your query loop using {echo:get_custom_loop_object_property(name)}
or {echo:get_custom_loop_object_property(phone)}
.
I hope there will be an easy (and documented) way to create custom dynamic tags soon. I’d prefer those over using {echo:xyz}
all the time. So @timmse, if you find the time…