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 610 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..

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 1)

This tutorial provides the PHP & JS codes that can be pasted in order to create a dynamic map with markers populated from a custom…
Categories:
Pro
6 Random Featured Posts in Alphabetical Order in Bricks

6 Random Featured Posts in Alphabetical Order in Bricks

How to output x number of random posts with a specific meta value set, in Alphabetical order.
Categories:
Pro
Alternating Posts from Two Post Types in Bricks

Alternating Posts from Two Post Types in Bricks

How to output posts from two seperate post types, alternating in a query loop.
Categories:
Pro
Bricks Query Loop for Top-level Parent Pages with Children

Bricks Query Loop for Top-level Parent Pages with Children

In the Bricks Facebook group, a user asked: Looking for a custom query to output a list of posts in the same hierarchy that the…
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

This tutorial provides the PHP & JS codes that can be pasted in order to create a flying effect on map markers each time your…