19th Nov '24
/
1 comment

Random Posts in the Same Category as the Current Single CPT Post in Bricks

Consider this scenario:

CPT: Practice Area
Taxonomy: Category (the built-in category taxonomy)

Requirement: When viewing single practice area CPT posts, show 4 random posts (the regular blog posts) that are assigned to the same category/categories as the current CPT.

Here’s how query loop can be set in Bricks to show related posts by a taxonomy’s terms:

Reference: Posts Related by Current Post’s Terms in Bricks.

If your category names have commas or other special characters, follow Related Posts by Taxonomy in Bricks instead for a more robust solution.

Get access to all 625 Bricks code tutorials with BricksLabs Pro

1 comment

  • Christopher Akins

    Inifintely easier than Oxygen. I was overthinking it. Thank you, Sridhar.

Leave your comment

 

Related Tutorials..

Pro
Bricks Query Loop – How to Insert Elements After Every Nth Post

Bricks Query Loop – How to Insert Elements After Every Nth Post

Update: Follow this tutorial instead. This Pro tutorial provides the steps to output element(s) in a Bricks' query loop after every nth post. Use case:…
Categories:
Pro
Non-empty events sorted by event date and other posts below in Bricks

Non-empty events sorted by event date and other posts below in Bricks

Updated on 15 Jan 2024 Consider a scenario where you are showing posts from multiple post types namely post, event and game in a single…
Categories:
Pro
6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

6 Random Posts from Tag A + 6 Random Posts from Tag B in a Single Bricks Query Loop

Displaying two set of random posts, inside one query loop.
Categories:
Pro
Dynamic Horizontal Posts Accordion in Bricks

Dynamic Horizontal Posts Accordion in Bricks

Creating a horizontal accordion of featured images from posts output by Bricks' query loop.
Categories:
Tags:
Adding any Custom WP_Query loop to Bricks’ Query Loop

Adding any Custom WP_Query loop to Bricks’ Query Loop

Sometimes we may need to create a custom post loop using Bricks' query loop feature, but wish to use our own WP_Query code for more…