9th Jan '24
/
0 comments

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

Related Tutorials..

Pro
Custom Meta Box Thumbnail Slider in WordPress

Custom Meta Box Thumbnail Slider in WordPress

This Pro tutorial provides the steps to set up an image and YouTube video thumbnail slider in WordPress using Splide and Meta Box. The site…
Categories:
Tags:
Pro
How to Inject a Different Type of Post in Bricks Query Loop

How to Inject a Different Type of Post in Bricks Query Loop

Updated on 26 Aug 2024 A user asks: Hello, I'd like to inject a CPT post card inside of a Bricks query loop of a different CPT…
Pro
HappyFiles Folder Images via Meta Box Taxonomy Field in Bricks Image Gallery

HappyFiles Folder Images via Meta Box Taxonomy Field in Bricks Image Gallery

How to set the source of Bricks’ Image Gallery element on a post to images in the selected HappyFiles Folder(s) via a Meta Box Taxonomy…
Pro
Meta Box Image Advanced Field Images in Bricks Query Loop

Meta Box Image Advanced Field Images in Bricks Query Loop

Updated on 3 Feb 2025 A user asked: Do you know what the best way to query an image from metabox gallery? I would like…
Categories:
Tags:
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
Post Data for the Current User in Bricks with Meta Box

Post Data for the Current User in Bricks with Meta Box

How to configure a query loop to output the post data of the SalesRep CPT associated with the current user.
Categories: