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

Related Tutorials..

Pro
ACF Image Data in Bricks

ACF Image Data in Bricks

Displaying Alt text, Caption, Title and URL of an ACF image field for posts in a query loop.
Categories:
Tags:
Pro
Alternating Posts from Two Post Types in Bricks

Alternating Posts from Two Post Types in Bricks

How to output posts from two seperate post types, alternating in a query loop.
Categories:
Pro
Child Posts Section in Bricks

Child Posts Section in Bricks

This Pro tutorial provides the steps to limit the posts (can be of any post type) output by Bricks' query loop to children of the…
Categories:
Pro
ACF Date Field Value Custom Format in Bricks

ACF Date Field Value Custom Format in Bricks

In the Bricks forum, a user asks: Hi there, I am setting up an events calendar using bricks. In some circumstances I would like to…
Categories:
Tags:
Pro
Non-empty events sorted by event date and other posts below in Bricks

Non-empty events sorted by event date and other posts below in Bricks

Updated on 15 Jan 2024 Consider a scenario where you are showing posts from multiple post types namely post, event and game in a single…
Categories:
How to create a dynamic infinite logo slider with ACF and Bricks

How to create a dynamic infinite logo slider with ACF and Bricks

This tutorial provides the builder settings, PHP & CSS codes that can be pasted in order to create an infinite logo slider in pure CSS…
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
Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Conditionally Outputting Query Loop Item Based on Post Meta in Bricks

Rendering query-loop enabled posts depending on the value of each post's custom field value is tricky because by default, the custom field plugins' functions or…
Categories:
How to apply a custom query var to multiple query loops in Bricks

How to apply a custom query var to multiple query loops in Bricks

In this tutorial, we'll learn how to apply a PHP filter to modify the query var of multiple query loops in a single function Introduction…
Categories: