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

Instant access to 390+ Bricks code tutorials with BricksLabs Pro