3rd Jul '25
/
2 comments

Filtering Bricks Posts Query Loop by Meta Box Group’s Radio Subfield Value

In the past we showed how a Bricks posts query loop can be filtered by Meta Box group’s subfield of types text/number and Datepicker here.

This Pro tutorial provides the steps to filter posts when the subfield is Radio type.

Consider this scenario:

CPT: store

Field group:

session (cloneable group)
|__ session_name (text)
|__ session_type (radio) with these choices:
|____ Individual
|____ Duet
|____ Trio

A post can have 1 or more sessions:

Another post:

The objective is to show all the posts for which session type is the specified string i.e., Individual or Duet or Trio.

Step 1

Set up query loop in a Page or Template.

Enable PHP query.

Paste:

$session_type = 'Individual';

// Validate session type
$valid_types = [ 'Individual', 'Duet', 'Trio' ];
if ( ! in_array( $session_type, $valid_types, true ) ) {
  return [ 'post__in' => [ 0 ] ]; // Return empty result for invalid session type
}

return [
  'post_type'      => 'store',
  'posts_per_page' => -1,
  'no_found_rows'  => true,
  'meta_query' => [ // Meta query to filter by session type
    [
      'key'     => 'session',
      'value'   => '"session__type";s:' . strlen( $session_type ) . ':"' . $session_type . '"',
      'compare' => 'LIKE',
    ],
  ]
];

Enter the session type to be filtered by in the first line in the above code.

"session__type";s:' . strlen( $session_type ) . ':"' . $session_type . '"

pattern creates a search string that matches the PHP serialized format of the ⁠session__type field within the Meta Box data, including the exact field name, string indicator, character count, and the value itself.

Sign code and save.

Step 2

Add a Post Title element inside the QL enabled Block.

That’s it! Now your query loop will be filtered to show only the posts that have at least 1 group with the matching Meta Box radio-type sub field.

Get access to all 612 Bricks code tutorials with BricksLabs Pro

2 comments

  • Joffrey Persia

    Where is the next part ?

    • A

      There's no second part.

      I've updated the tutorial to add:

      > That's it! Now your query loop will be filtered to show only the posts that have at least 1 group with the matching Meta Box radio-type sub field.

Leave your comment

 

Related Tutorials..

Pro
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories:
Pro
Dynamic Horizontal Posts Accordion in Bricks

Dynamic Horizontal Posts Accordion in Bricks

Creating a horizontal accordion of featured images from posts output by Bricks' query loop.
Categories:
Tags:
Latest Featured Posts First in Bricks Query Loop (No Duplicates)

Latest Featured Posts First in Bricks Query Loop (No Duplicates)

In the Bricks Facebook group a user asks: We can use AI to help unfreeze our brains sometimes or at least have it write the…
Categories:
Pro
Meta Box Group’s Number Sub Field Values Sum

Meta Box Group’s Number Sub Field Values Sum

In the Bricks Facebook group a user asked: We can define a custom function that takes a Meta Box group ID, the sub field ID…
Categories:
Tags:
Pro
Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering a query loop to output only those posts with the value of a Select subfield of a Group field set to Yes when using…
Categories:
Tags: