8th Mar '23
/
2 comments

Posts Grouped by ACF or Meta Box Select Field Value as Tabs in Bricks

Updated on 9 Mar 2023: Added Meta Box specific instructions.

This Pro tutorial provides the steps to show labels of an Advanced Custom Fields' Select-type of field as the tab titles and a list of all posts that have the corresponding meta value as the tab content when using Bricks' Tabs (Nestable) element.

Whilst it is possible to manually set the tab titles and multiple query loops in each tab content, the benefit of this method is that it is dynamic and needs no maintenance. The site admin or client can at any time simply change the choices of the select field, the order of the choices and the tabs will automatically reflect these changes.

In this example we are going to be dealing with a task custom post type that has a task_status custom field.

We shall

  • add a new "Task Status" type control to query loop options - in the dropdown.
  • create a function that should run when the above query type is selected in which we
    • get the ID of the latest task post
    • get all the task statuses for any post of the task post type
    • create and return an array having key and label named keys
  • create another function for returning the label or the key for the current task status being looped through for use with Bricks dynamic data tags.
  • apply our custom query to Tab menu > Div and call the second function that returns the choices' labels for the tab titles.
  • apply our custom query to Content > Pane and inside that, a Block with a Posts query to pull all the entries of the task CPT where task_status meta equals the choice key.

Step 1

Create your custom field group having a Select type of field with choices having value : label pairs and attach it to your post type.

Make sure that Return Format is set to Both (Array).

Step 2

Create/edit your post/CPT items and populate the custom field for each.

Step 3

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

Get access to all 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

How to create filters with IsotopeJS in Bricks (Part 1)

How to create filters with IsotopeJS in Bricks (Part 1)

This tutorial series will explore the IsotopeJS library's features inside the Bricks ecosystem.
Categories:
How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

How to create filters with IsotopeJS in Bricks (Part 3): apply multiple filters

This tutorial will review how to apply multiple filters to an isotope container using the IsotopeJS library‘s features in Bricks.
Pro
Customizing ACF Repeater/Relationship or Meta Box Relationship Query Parameters in Bricks

Customizing ACF Repeater/Relationship or Meta Box Relationship Query Parameters in Bricks

For query types other than post, term and user in Bricks i.e, ACF Repeater/ACF Relationship/Meta Box Relationship there are no built-in controls for modifying the…
Categories:
Pro
Filtering Query Loop Posts by a Non-empty Custom Field in Bricks

Filtering Query Loop Posts by a Non-empty Custom Field in Bricks

This Pro tutorial shows how we can prefilter the results of a query output by a Bricks query loop to only those for which the…
Categories:
Tags:
Pro
Programmatically populating ACF field values in WordPress

Programmatically populating ACF field values in WordPress

An example of how to set the values of a Select-type field with the names and labels of all public post types.
Categories:
Filtering Breadcrumbs in Bricks

Filtering Breadcrumbs in Bricks

Using the bricks/breadcrumbs/items filter to modify Bricks' breadcrumbs’ element programmatically.
Categories:
Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Removing Action/Filter Inside a Plugin’s Namespaced Class Constructor

Recently worked with a friend figuring out how to remove/undo/cancel an add_action() line that's inside a plugin's constructor inside a PHP Class with the file…
Categories:
Tags: