If anyone can point me toward a tutorial or any code for this or tell me how to debug this, I’d be incredibly grateful.
I have a CSS Grid. I have seven blocks in the grid that each use a query loop to pull a random post. I want to avoid duplicates when the posts load in the blocks. What would be the best method to do this?
When I apply a query loop to show 7 posts, it shows seven posts inside of the block (see the image). When I apply a query loop to show 7 posts to the block that wraps the block, it duplicates that block seven times and doesn’t fill the other blocks. When I apply the query loop to the container grid, the container that wraps the container grid, or the section, it duplicates the entire grid 7 times and each block in each duplicate grid is the same post repeated seven times.
I also tried to create a new query, but I’m very new to all of this and don’t know where I’m going wrong. I debugged it a bit and it seems to be getting post IDs, but something’s wrong with it not applying it properly when I set the “Type” in the query loop to “Random Unique Posts.”
I don’t know if I’m overthinking this and not seeing an easier answer. I’ve been trying everything I can think of to get this to work for days, but I feel more out of my depth the more I try to get it to work.
This is the query code, but I’m pretty sure it has major issues:
The blocks have different styling with custom css and some of the blocks won’t contain post data. The top grid is I want the layout to look like, just without the duplicate posts. If I delete the rest of the blocks, it looks like the bottom grid, so I lose the styling and span.
In that case, would I do something like write nth-child CSS to style the grid and put it in the container grid’s custom CSS?
Thanks. I was able to get it figured out by adding this code to functions.php and the other code to the Query Editor (PHP). There’s a ton of styling and other stuff that I didn’t want to rewrite as nth-child. The code below doesn’t duplicate posts on each refresh. Leaving this up in case anyone deals with this in the future.