17th Sep '24
/
3 comments

ACF Select Field Query Types in Bricks

In the BricksLabs Facebook group a user asks:

Hi all, I am building a single post template for a CPT and want to know if I can work more effectively with some ACF data.

With the ACF Select Field, I would like a way I can return the selected items and work with the data in bricks more effectively, Currently I am using a snippet to return the selections > https://codefile.io/f/G1fLgmJ6ee

This works by returning each choice separately, but it removes the workflow from within the builder, and I have to start writing custom CSS, etc., instead of applying a class to an element and styling it in the builder.

Is there a better way I can do this that allows me to keep using the builder to edit elements live and see the correct design/output in the builder? I have a ton of these to do and hope there is a better way.

This Pro tutorial provides the steps to register

  • a custom query type for a specific ACF select field
  • custom query types for all ACF select fields automatically
    • with the corresponding dynamic tags to be used in the editor for outputting the selected choices

Custom query type for a specific ACF select field

Consider this field group:

For the "Sample Page", I have Bricks and Breakdance selected:

After implementing the tutorial, a new "WordPress Page Builders Query" query type will be available

and a new dynamic tag:

to get the output:

Custom query types for all ACF select fields

Field groups:

(in addition to the earlier one)

Sample Service CPT post:

After implementing the tutorial, these query types will be available: "Service Locations (ACF Select)" and "WordPress Page Builders (ACF Select)" with these corresponding dynamic tags:

{bl_acf_service_locations_value}

{bl_acf_wordpress_page_builders_value}

Custom query type for a specific ACF select field

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

Related Tutorials..

How to conditionally load your scripts based on an ACF field

How to conditionally load your scripts based on an ACF field

This tutorial provides the PHP codes that can be pasted in order to enqueue your scripts conditionally based on the value of an ACF field…
Categories:
Pro
Dynamic Horizontal Posts Accordion in Bricks

Dynamic Horizontal Posts Accordion in Bricks

Creating a horizontal accordion of featured images from posts output by Bricks' query loop.
Categories:
Tags:
Pro
ACF Post Object Query Loop inside a Posts Query Loop in Bricks

ACF Post Object Query Loop inside a Posts Query Loop in Bricks

How to loop through a CPT and within each post, output a list of related posts.
Categories:
Pro
Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Upcoming Events in Bricks Grouped by ‘Month Year’ with Frontend Filtering by Event Type

Updated version of the earlier Upcoming Events Grouped by ‘Month Year’ in Bricks tutorial with some improvements:
Pro
Sub Field Value from the Last ACF Repeater Row in Bricks

Sub Field Value from the Last ACF Repeater Row in Bricks

Getting the value of a specific sub field of an ACF Pro‘s Repeater field and output in the query loop.
Categories:
Tags:
Pro
ACF Options Fields in Bricks

ACF Options Fields in Bricks

This Pro tutorial walks you through outputting the values of custom fields attached to an ACF Pro's Options page in Bricks builder. We shall register…
Categories:
Pro
Outputting an Element in Bricks x times where x is a custom field value

Outputting an Element in Bricks x times where x is a custom field value

Learn how to output a query loop item(s) as many times as the value of a custom field in Bricks.
Categories: