Filter: bricks/query/result
Available since Bricks 1.8, bricks/query/result lets you modify fetched query results before the loop renders them. The result type depends on the query: a native post query returns a WP_Query object, while an ACF loop can return an array. Use bricks/query/run when adding a custom query type.
Sort post results
Section titled “Sort post results”// Use this filter to rearrange it by post title (PHP way instead of query orderby)add_filter( 'bricks/query/result', function( $result, $query_obj ){ // Return: Element ID is not "djvsvi", nor is it a post query if ( $query_obj->element_id !== 'djvsvi' || $query_obj->object_type !== 'post' ) { return $result; }
// Sort by post title (descending) // Result is WP_Query object with posts if ( $result->have_posts() ) { $posts = $result->posts;
usort( $posts, function( $a, $b ) { return strcmp( $b->post_title, $a->post_title ); });
$result->posts = $posts; }
return $result;}, 10, 2 );Slice an ACF array
Section titled “Slice an ACF array”For an ACF Relationship loop that returns an array, use a result filter scoped to the loop element to skip or limit items. Replace abc123 with the loop element’s raw Bricks ID, without the brxe- prefix or a #.
This example skips the first item and returns up to three of the remaining items:
add_filter( 'bricks/query/result', function( $result, $query ) { if ( $query->element_id !== 'abc123' || ! is_array( $result ) ) { return $result; }
return array_slice( $result, 1, 3 );}, 10, 2 );With four items in the ACF array, the loop renders the second, third, and fourth items in their existing editorial order. The saved ACF entries remain unchanged. To keep the first item and display up to three items, use array_slice( $result, 0, 3 ) instead.
Slicing here does not automatically recalculate the query’s total count, maximum number of pages, or summary positions. If the loop has a summary or pagination, keep that metadata consistent with the intended behavior using bricks/query/result_count, bricks/query/result_max_num_pages, bricks/query/result_start, and bricks/query/result_end. A fixed slice does not fetch another page.
For native query limits and offsets, use the Query Loop controls. The result_start and result_end filters change summary metadata only; they do not slice the results.
Was this helpful?
A quick vote and short notes help us improve these docs faster.
Leave a note for us
Please do not include passwords, license keys, or personal data. We store submitted notes to improve the docs.
Thanks for sharing feedback. We're using it to improve these docs.