Related Posts using Meta Box in Bricks

This Pro tutorial provides the steps to show posts set as related to the current single post via a Meta Box Post-type of field in Bricks.

Note

This can be applied to entries of any post type, not just post.

Step 1

Create a custom fields group having a Post type of field.

Tick "Multiple".

Step 2

Edit your entries and selected the related posts.

Step 3

Edit your single post template with Bricks.

Add a Section and inside its Container, a Related Post h2 heading.

We are going to programatically append s to the above heading text if there is more than 1 related post for the current single post.

Add a Container and inside it, a Block.

Enable query loop on the Block.

Click the loop icon and set Posts per page to -1.

Add a Post Title element (h3 HTML tag) inside the Block and enable "Link to post".

You should now have a section that shows all the posts in the site on every single post.

In the next step we shall

  • add a query variable to limit the posts to only the related posts
  • create a custom function to get the number of related posts
  • append s to the heading element's text when the number of related posts is greater than 1

Step 4

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to all 250+ Bricks code tutorials with BricksLabs Pro