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

Pro
Recently Viewed Posts Bricks Query Loop

Recently Viewed Posts Bricks Query Loop

How to output the most recent X number of posts (any post type) viewed by the current visitor.
Categories:
Pro
Related Services grouped by Service Categories on Single Branch Posts in Bricks

Related Services grouped by Service Categories on Single Branch Posts in Bricks

How to query ACF relationship fields on single CPT templates.
Categories:
Pro
Term Parent Slug Data Attribute in Bricks

Term Parent Slug Data Attribute in Bricks

How we can set a data attributes on a child taxonomy dynamically based on the parent taxonomy.
Categories:
Pro
Adjacent Posts Bricks Query Loop

Adjacent Posts Bricks Query Loop

This Pro tutorial provides the steps to customize a posts query loop in Bricks to show previous and next posts on single post pages. The…
Categories:
Pro
Post Views Counter Query Loop in Bricks

Post Views Counter Query Loop in Bricks

How we can output the most viewed posts in your Bricks site in a query loop.
Categories:
Pro
Upcoming Events Grouped by ‘Month Year’ in Bricks

Upcoming Events Grouped by ‘Month Year’ in Bricks

A custom query loop type for showing future events based on a date custom field using three nested query loops.
Pro
Posts older than today in Bricks

Posts older than today in Bricks

How to display only posts that were published before today in a query loop.
Categories: