Custom Field Value based Adjacent Posts Navigation Query Type in Bricks

David Browne wrote Building Prev / Next Posts with Query Loops in Bricks tutorial in the past in which he showed how to add a custom "Adjacent Posts" option in the Query type dropdown for Bricks' query loops. The previous and next posts were based on the post's published date.

This Pro tutorial is a variation of the above for single posts where the previous and next posts are based on the value of a number-type custom field.

We are going to add a "Post Number" custom field using ACF (any other plugin like Meta Box /method can also be used), then assign numbers like 1, 2, 3, 4 (need not be sequential although it helps if they are). The objective is to show Post 2 as the previous post and Post 4 as the next post when viewing Post 3 for example.

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 524 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

This tutorial will explain how to enable the AJAX filter with an infinite scroll query loop container, how to add a sorting function, how to…
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:
bricks/posts/merge_query Explained

bricks/posts/merge_query Explained

This short article provides details on Bricks' bricks/posts/merge_query filter. On pages rendered by an archive or search template, secondary queries like the ones used for…
Categories:
Tags: