By the way…
You can of course also do other things inside the function and change the results.
Like in this example below, first all posts without status “publish” are removed and then the remaining posts are sorted by title a-z.
Cheers
Patric
<?php
add_filter( 'bricks/query/result', function( $result, $query_obj ){
// Return: Element ID is not the target one, an ACF Relationship query
if ( $query_obj->element_id !== 'rtzlnn') {
return $result;
}
// in the example below, only posts with status "published" are kept
if (!empty ($result)) {
$keys = array_keys(array_combine(array_keys($result), array_column($result, 'post_status')),"publish");
$result = (array_intersect_key($result, $keys));
// and now we sort...
$title = array();
$z = 0;
foreach( $result as $item ) {
$z = $z + 1;
// for this example I retrieve the title of the post
$title[$z] = get_the_title( $item->ID );
}
array_multisort($title, $result);
}
return $result;
}, 10, 2 );