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
Let’s define a global variable called $displayed_posts to keep track of the IDs of the posts output by the first query loop.
Add the following in child theme‘s functions.php (w/o the opening PHP tag) or a code snippets plugin:
// Create a global variable to store post IDs in the first query loop
global $displayed_posts;
// Set it to an empty array
$displayed_posts = [];
Step 2
Edit your page with Bricks.
Set up the first query loop like this:

Set Random seed TTL to 0.
Set Posts per page to a specific number or leave it default to use the setting from WordPress General settings.
Add a Code element inside the first query loop.
<?php
global $displayed_posts;
$displayed_posts[] = BricksQuery::get_loop_object_id(); // add ID of posts in the loop
?>
Execute code and Sign code.

In each iteration of the loop, the post ID gets added to the $displayed_posts array.
Step 3
We need to exclude the posts whose IDs are stored in the $displayed_posts array from the second query.
Enable PHP query editor and paste:
global $displayed_posts;
return [
'post_type' => 'post',
'posts_per_page' => 5,
'orderby' => 'rand',
'post__not_in' => $displayed_posts,
'bricks_force_run' => true // disable reuse of query results
];
Check on the front end.
When there are more than 2 query loops

Repeat Step 3 for every query other than the first one.
Reference
https://wpdevdesign.com/excluding-duplicate-posts-from-repeaters-easy-posts/