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 633 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
WordPress Posts using WP REST API in Bricks

WordPress Posts using WP REST API in Bricks

The steps to display posts from any WordPress site that has WP REST API enabled in Bricks builder using a custom query type.
Categories:
Pro
Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Updated version of the earlier Upcoming Events Grouped by ‘Month Year’ in Bricks tutorial with some improvements:
Pro
Ordering Posts by Terms in Bricks

Ordering Posts by Terms in Bricks

How to output upcoming events at the top and past events below in a single query loop in Bricks.
Categories:
Pro
Meta Box Image Advanced Field Images in Bricks Query Loop

Meta Box Image Advanced Field Images in Bricks Query Loop

Updated on 3 Feb 2025 A user asked: Do you know what the best way to query an image from metabox gallery? I would like…
Categories:
Tags:
Pro
How to Query WordPress Taxonomy Terms by Hierarchy Level in Bricks

How to Query WordPress Taxonomy Terms by Hierarchy Level in Bricks

How to limit the terms of a Bricks Terms query to only those at a specific level within the taxonomy hierarchy.
Categories:
Pro
Post Views Counter Query Loop in Bricks

Post Views Counter Query Loop in Bricks

How we can output the most viewed posts in your Bricks site in a query loop.
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

This tutorial provides the PHP & JS codes that can be pasted in order to create a flying effect on map markers each time your…