26th Jul '24
/
5 comments

Remove Duplicate Term Names From Bricks Terms Query Loop

Remove Duplicate Term Names From Bricks Terms Query Loop

Updated on 2 Aug 2024

Consider this scenario:

CPT: OfferCustom taxonomy: Offer Type

Sample offer types:

Output of Bricks terms query loop for the Offer Type taxonomy:

Remember that terms are ordered by name in ascending order by default.

This Pro tutorial shows how to exclude terms with duplicate names from a Bricks terms query while keeping the first occurrence of a term name and excluding any subsequent terms with the same name.

This can be useful when you want to ensure unique term names are displayed, perhaps to avoid confusion or to clean up the presentation of terms in a particular terms query loop.

After implementing the tutorial:

Step 1

Set up your terms query loop.

Step 2

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 613 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Prefiltering Bricks Terms Query Loop

Prefiltering Bricks Terms Query Loop

Let's say there's a Events CPT with a 'Event Year' custom taxonomy. Sample event year names could be: 2021, 2022, 2024, 2025, 2028 etc. We…
Pro
Primary Term for Posts using The SEO Framework in Bricks

Primary Term for Posts using The SEO Framework in Bricks

Updated on 18 Mar 2024 The SEO Framework is one of the better (coding-wise) SEO plugins. Like Yoast and Rank Math, it has the option…
Pro
Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Updated on 29 Feb 2024 In the Sibling Terms Bricks Query Loop tutorial, a member asked: How can I set the class "active" to the…
Categories:
Pro
Term Parent Slug Data Attribute in Bricks

Term Parent Slug Data Attribute in Bricks

How we can set a data attributes on a child taxonomy dynamically based on the parent taxonomy.
Categories:
Pro
Current Post’s Terms in Bricks

Current Post’s Terms in Bricks

Updated on 15 Jan 2024 This Pro tutorial provides the steps to set up a grid of terms (like categories) that the current post is…
Pro
Filtering a Bricks Terms query on Term archive pages

Filtering a Bricks Terms query on Term archive pages

On product category archives, how to show product type names but only those that the current product category has.
Pro
Category Grid with ACF Images in Bricks

Category Grid with ACF Images in Bricks

Creating a grid of post categories, each category card showing an image from an ACF field, category name & description.
Categories:
Pro
aria-current=”true” for Current Categories on single Posts in Bricks

aria-current=”true” for Current Categories on single Posts in Bricks

How to separately style only the category links that are assigned to the current post.
Categories: