22nd Nov '22
/
11 comments

Excluding Duplicate Posts from Query Loops in Bricks

Updated on 16 Oct 2024

This Pro tutorial provides the steps to ensure that posts are not duplicated when two or more query loops are used on the same page in Bricks.

Let's take a sample scenario where we have 2 query loops.

  • The first query loop shows 6 random testimonials.
  • The second query loop is also set to show 6 (or can be any number of) random testimonials.

Since the posts are random, it is possible to have the same post(s) appear in both the loops at any given time.

After implementing this tutorial, any posts that may be output in the first query will not be included in the posts output by the second query.

Update on 16 Oct 2024: Added instructions near the end for when there are more than 2 query loops.

Step 1

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 609 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Displaying Gallery of SureCart Product Images with Bricks’ Query Loop

Custom query loop for looping through SureCart product images.
Categories:
Tags:
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
Current Single Post Reference From Inside a Bricks Query Loop

Current Single Post Reference From Inside a Bricks Query Loop

Use case: Get the single post’s custom field (like ACF Repeater or Meta Box Group) array row corresponding to the loop’s counter/index
Categories:
Pro
Posts Grouped by Month and Year in Bricks

Posts Grouped by Month and Year in Bricks

Nesting query loops with months & years in descending order, with the inner loop outputting the posts.
Categories:
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
Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

Nested Meta Box Query Loop Inside a CPT Query Loop in Bricks

This Pro tutorial provides the steps for setting up a cloneable Meta Box group query inside a CPT query in Bricks. Scenario: CPT: course Meta…
Categories: