Following on from our tutorial on Adding Custom WP_Query Loops in Bricks, in this pro tutorial we'll walk through the process of using those same Bricks' filters to allow us to build custom adjacent posts ( or prev/next posts ) for use on a single post template.
We can then set up this query on the container element, meaning we can then build the layout how we like by placing elements inside and using any dynamic data from those posts. This gives us much more flexibility than using the native 'post navigation' element.
Adding the Adjacent Post Query
This code would need to be added outside of the builder, either inside your child themeโs functions.php file or a code snippet manager such as WPCodeBox.
This is a BricksLabs Pro tutorial.
For full access login below or create your BricksLabs Pro account
7 comments
Maddalena Fasser
Like the other users, I’m also looking to sort the previous and next posts based on a custom numeric field, created using MetaBox. Would you be able to provide some guidance on how to achieve this? Thank you in advance! ๐
Sridhar Katakam
Done. https://brickslabs.com/custom-field-value-based-adjacent-posts-navigation-query-type-in-bricks/
Sridhar Katakam
This needs custom coding. I am working on this. Will post a new tutorial once I have it working.
Sebastian Albert
Hello again!
Is there a possibility to sort the Adjacent Post Query by an ACF field (meta_key), so that it matches the overview page?
Sridhar Katakam
Better late than never.
Done. https://brickslabs.com/custom-field-value-based-adjacent-posts-navigation-query-type-in-bricks/
Sebastian Albert
Hello,
Thanks for the tutorial.
I have the post archive sorted by a ACF number value. Is it possible to align the sorting of the prev/next button to the same ACF number value?
If I implement the code as is, the sorting of the archive and the prev/next buttons does not line up, as they seem to be sorted by a different value.
Thanks!
Sebastian Albert
Sadly there is no answer for over 1 month…. Hello????