28th Oct '25
/
0 comments

Frontend Search Filtering by Post Title, Content and Related Post’s Title in Bricks

Update: Also added Variation 2 with support for Bricks' Load more functionality.

In the Bricks Facebook group a user asked:

Hello everyone. I have this issue with filtering and bi-directional relationships between 2 CPTs. I have made a query loop with the CPT "Sample packs" and need the CPT "Artists" post title in it. So I did the following (see image). This worked perfectly, but now filtering is an issue. Searching for the artist name, with the article card selected as target query doesn't seem to work, neither does targeting the artist name query.

Hope someone can help me out 🥹

Also having some trouble with this actually, as I need a way to display a “,” or something like that between the 2 artist names in the query loop

This Pro tutorial provides the steps to

  1. output comma-separated titles of artist CPT posts related to the current sample-pack CPT post (in the loop)
  2. add a search input that lets the visitors search across titles, excerpts, and artist names simultaneously, with a results counter showing how many packs match the search query

on the Sample Pack CPT's archive page (or on a standard Page, if you choose to).

Note

This solution will NOT work properly with pagination. The JavaScript only searches through posts that are currently loaded in the DOM (i.e., only the posts on the current page).

If you don't have too many sample packs (under 50-100), disable pagination and show all posts in your Bricks query settings by setting Posts per page to -1 or a high number.

Step 1

Create your CPTs and add a field group for each using ACF having a bidirectional Relationship field.

Add Artist and Sample Pack posts. Select related posts of the other post type.

Step 2

This step is optional and if you prefer, you could just use a standard Page.

Where possible, it is better (pedagogically speaking, not so much practically) to use a CPT archive page instead of a static Page since the query will be default vs a custom one.

Edit Sample Pack CPT, ensure that Archive is enabled and set your desired archive slug.

Create a Bricks template for the CPT archive and add the condition.

Step 3

Let's create two custom functions.

  1. that returns comma-separated artist titles for the current sample pack (in the loop)
  2. that returns searchable data (JSON-encoded string) for sample pack filtering

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

Bidirectional Relationship between a CPT and a Taxonomy of another CPT using ACF in Bricks

A couple of members asked: I have a cpt called "Markets" aand a cpt "tools". Tools have a taxonomy "tools group". How can i create…
Pro
ACF Flexible Content Field – Layout Labels and Sub Field Labels

ACF Flexible Content Field – Layout Labels and Sub Field Labels

How to output the text of layout labels and/or sub field labels using the Flexible Content field of ACF Pro.
Categories:
How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

This tutorial will review how to apply multiple filters to an isotope container using the IsotopeJS library‘s features in Bricks.
Pro
Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

On product pages, we show all the FAQs associated with the current WooCommerce product's product categories.
Categories:
Pro
ACF Image Data in Bricks

ACF Image Data in Bricks

Displaying Alt text, Caption, Title and URL of an ACF image field for posts in a query loop.
Categories:
Tags:
Pro
Sorting ACF Relationship Posts by Date Meta in Bricks

Sorting ACF Relationship Posts by Date Meta in Bricks

Consider the following setup: CPT: Events ACF Fields:Event Date Information (Group)|__Event Date (Date Picker)Pick Sub Events (Relationship) An Event can have 1 or more related…
Pro
Querying Posts by Date/Datetime Custom Fields in Bricks

Querying Posts by Date/Datetime Custom Fields in Bricks

This Pro tutorial shows how to configure ACF and Meta Box to query posts in Bricks by custom field(s) of the type Date/Date Time Picker…
Categories:
Tags:
Pro
Conditional Output based on Date Time Picker Field in Bricks

Conditional Output based on Date Time Picker Field in Bricks

In the past, we showed how elements can be conditionally output based on a post's Date type of ACF field here. This Pro tutorial for…
Categories: