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ā¦
Iām trying to return results from a json file. It works if I use return json_decode($file, true).
But I canāt figure out how I could define the maximum number of items, similar to posts_per_page. Iāve tried array_slice, but then I canāt use a load more button.
Hello, Iāve achieved interesting things with this, just wanted to share and thank yāall for the knowledge you shared here. Wouldnāt have a clue where to start off without this thread. Check out this video.
The function get_custom_loop_object_property( ) successfully inserts a value into a heading element, but that function cannot access the $query_loop within a Code element or a subquery in the Query Editor.