Updated on 4 Feb 2024
This Pro tutorial provides the steps to show posts marked as featured at the top and then the other posts below them (sorted either by title or date) in Bricks.
Testimonial posts list:
On frontend:

Step 1
Use your favorite custom fields plugin to set up a custom field whose value gets saved as 0 or 1. This could be ACF’s True / False or Checkbox or Meta Box’s Switch field.
We used a Meta Box Switch-type field in our test site.

Step 2
Edit your template/Page with Bricks and add a Section.
Inside the Section’s Container, add a Posts element or a query loop-enabled Block.
Edit the query and select your post type if needed.
Next, we shall
- filter the posts by those having “featured” post meta set to 1 OR those not having “featured” post meta set or with “featured” post meta set to 0
- and set the orderby as needed
Add this in child theme‘s functions.php or a code snippets plugin:
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if ( $element_id === 'qtcwtd' ) {
$query_vars['no_found_rows'] = true;
$query_vars['update_post_meta_cache'] = false;
$query_vars['update_post_term_cache'] = false;
// filter the posts by those having "featured" post meta set to 1 or those not having "featured" post meta set
$query_vars['meta_query'] = [
'relation' => 'OR',
'featured_clause' => [
'key' => 'featured',
'value' => 1,
],
'no_featured_clause' => [
'relation' => 'OR',
[
'key' => 'featured',
'compare' => 'NOT EXISTS',
],
[
'key' => 'featured',
'value' => 0,
],
],
];
// sort the posts that don't have "featured" post meta set first,
// then sort the posts that have "featured" post meta = 1
// sort both these groups in ascending order of title
$query_vars['orderby'] = [
'no_featured_clause' => 'DESC',
'title' => 'ASC',
'featured_clause' => 'DESC',
];
}
return $query_vars;
}, 10, 3 );
Replace qtcwtd with the Bricks ID of your Posts/query loop element.
If you wish the sort order to be descending order of dates instead of by titles, replace
'title' => 'ASC',
with
'date' => 'DESC',
Note: When using this for WooCommerce products, use a priority of 20 instead of 10.
For product post type, please use higher value priority as Bricks has code hooked on ‘bricks/posts/query_vars’ at priority 10 as well.
Sometimes if you placed your code in child theme, the priority playing important rule.– Bricks support team
