In the BricksLabs Facebook group a user asks:
Any idea how to set the sort order of a cloneable group in the query? In this case, I just need to sort social media accounts alphabetically. I know it can be done manually, but that isn't a viable option with multiple people entering content.
In the past, we showed how posts could be sorted/ordered by a Meta Box group field's sub-field value in the Sort Posts by Meta Box Group Sub Field in Bricks tutorial.
This Pro tutorial shows a relatively simplified case of the above where we want to order the rows of a Meta Box group by the value of one of its sub fields in Bricks.
Given this Meta Box group (JSON export below the screenshot):
JSON export of the field group
let's say, for a specific post the group-type field is populated like this:
With the Meta Box group query type for a query loop in the single post Bricks template like this:
The output on the single post will be:
After implementing this tutorial, it will become:
i.e., the results are sorted in ascending order of the account type (sub field value).
Solution
Add the following in child theme's functions.php
(don't include the opening PHP tag in this case) or a code snippets plugin:
This is a BricksLabs Pro tutorial.
For full access login below or create your BricksLabs Pro account