Ordering Meta Box group rows by a sub field in Bricks

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

Get access to all 524 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Dynamic Source for Video Element in Bricks Using Meta Box Post Field

Dynamic Source for Video Element in Bricks Using Meta Box Post Field

This Pro tutorial provides the steps to set the source of a Bricks video element on single CPT pages to be the URL of a…
Categories:
Pro
Adding FAQ page Schema with SlimSeo Schema & Meta Box

Adding FAQ page Schema with SlimSeo Schema & Meta Box

SlimSeo Schema is a plugin by the people behind both SlimSEO & Meta Box. It takes care of adding all the page schema across your…
Categories:
Pro
Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

Filtering posts by a group field’s true / false field sub field value with ACF or Meta Box in Bricks

This Pro tutorial covers how posts of a Bricks query loop can be filtered to show only the ones whose true / false or checkbox…
Categories:
Tags:
Pro
How to Modify Products Element Query in Bricks to Output Child Products

How to Modify Products Element Query in Bricks to Output Child Products

This Pro tutorial provides the steps to limit WooCommerce products output by Bricks' Products element on single product pages to only the children of the…
Meta Box Category Colors in Single Posts

Meta Box Category Colors in Single Posts

Looking to use Meta Box Color Picker fields' values in a single post Bricks template based on the post category? This tutorial shows how. Note:…
Categories:
Tags:
Pro
x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

Showing how to display one random row of a Meta Box group for an hour and then output another random row.