19th Mar '24
/
6 comments

CPT Posts Grouped by Custom Taxonomy Terms in Bricks

A user asked via email:

I need some help with querying custom taxonomies in Bricks and I hope you could help me with that.

I have CPT created with Metabox called Services. I also created a custom taxonomy called Service Category.

I want to create a query that will first show all of the terms, and then inside this query there should be one more query, that will be querying through the services from this particular taxonomy.

Everything is working apart from the second inner query, I cannot get it to filter and show only services that are part of this current particular query, it is always showing all services, and I do not know how to solve this problem.

To give you some more context, here's the link showcasing how it should look like, I'm currently building it as a static page, as I did not find any other solution:

This Pro tutorial provides the steps to set up an outer Service Category terms loop and an inner Service posts loop in Bricks without writing a single line of code.

This works with posts of any post type and terms of any taxonomy incl. categories.

Step 1

Register your CPT and the associated custom taxonomy using Meta Box or ACF or CPT UI or otherwise.

CPT:

Custom Taxonomy:

Resave permalinks.

Step 2

Add posts of your CPT and select the corresponding terms for each.

Step 3

Create a template called say "Services" of the type Archive.

Edit it with Bricks.

Add a template condition to make it apply to your CPT archive page.

Copy the below JSON code and paste to import a Section having this structure:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 626 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Mixed Post Types Grid in Bricks

Mixed Post Types Grid in Bricks

How to set up a mixed post types grid in Bricks, where you can display both standard posts and custom quote cards in alternating positions.
Categories:
Pro
Post-specific ACF Repeater Galleries as Sliders in Bricks

Post-specific ACF Repeater Galleries as Sliders in Bricks

How to output ACF Repeater field rows with the images of the Gallery-type sub field as a slider.
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
Top-level Pages and Children Bricks Query Loop

Top-level Pages and Children Bricks Query Loop

This Pro tutorial for Bricks users can be considered Part 2 or a variation of the earlier Bricks Query Loop for Top-level Parent Pages with…
Categories:
Pro
Custom SQL Ordering for Sorting Events in Bricks

Custom SQL Ordering for Sorting Events in Bricks

Showing events ordered by the event date with upcoming events in ascending order and past events in descending order.
Categories:
Pro
Related Services grouped by Service Categories on Single Branch Posts in Bricks

Related Services grouped by Service Categories on Single Branch Posts in Bricks

How to query ACF relationship fields on single CPT templates.
Categories:
Pro
“My Favorites” in Bricks

“My Favorites” in Bricks

This Pro tutorial provides the steps to set up and use My Favorites in Bricks Builder.
Categories: