Related Posts by Taxonomy in Bricks

 Related Posts by Taxonomy in Bricks

In the previous Posts Related by Current Post's Terms in Bricks tutorial, we showed how posts related to the current single post that have the same terms as the current post can be configured in a Bricks query loop.

That method is not reliable esp. in situations when the terms have commas and other special characters in them. This tutorial addresses this question a user asked in the comments section there:

I got this working on my page but for some reason it's not working for taxonomies that have commas in them, like "Cancer, Heart Attack, and Stroke" or "Dental, Vision, and Hearing" It displays fine for other Taxonomies without commas

This Pro tutorial provides the steps to use PHP query editor of a Bricks query loop to output x number of posts (of any post type) related to the current single post by a specified taxonomy.

After implementing the tutorial you could simply paste

return bl_get_related_posts_query();

in a query loop's PHP editor and sign code to output 5 posts that have the same category/categories as the current single post being viewed.

or for example,

return bl_get_related_posts_query( 'project', 'project-type', 7 );

to output 7 project CPT posts that have the same project-type custom taxonomy terms as the current single project being viewed.

Step 1

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 537 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Auto Responsive Grids in Bricks

Auto Responsive Grids in Bricks

This tutorial provides the CSS that can be pasted for automatic responsive grids in Bricks Builder. Posts element Each post will get a right padding…
Pro
Posts Grouped by Month and Year in Bricks

Posts Grouped by Month and Year in Bricks

Nesting query loops with months & years in descending order, with the inner loop outputting the posts.
Categories:
Related Posts by Author in Bricks

Related Posts by Author in Bricks

Querying posts on single posts by the author of the current post.
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…
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.
Displaying SureCart Featured Products & Products Collections with a Query Loop

Displaying SureCart Featured Products & Products Collections with a Query Loop

We walk through how to use a query loop to display SureCart products, featured products & collections.
Categories: