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

Related Tutorials..

Pro
CMB2 Repeatable Group Bricks Query Loop

CMB2 Repeatable Group Bricks Query Loop

This Pro tutorial provides the steps to create a custom query loop type for outputting the subfield values of a Group field (repeatable) when using…
Pro
Events grouped by Event Date custom field in Bricks

Events grouped by Event Date custom field in Bricks

This Pro tutorial for Bricks users provides the steps to output posts of an event custom post type dynamically grouped by the value of their…
Categories:
Filtering Bricks Posts Query Loop by Meta Box Group’s Radio Subfield Value

Filtering Bricks Posts Query Loop by Meta Box Group’s Radio Subfield Value

In the past we showed how a Bricks posts query loop can be filtered by Meta Box group's subfield of types text/number and Datepicker here.…
Categories:
Pro
Bricks Slider Images From ACF Flexible Content Sub Field

Bricks Slider Images From ACF Flexible Content Sub Field

Consider the following field group associated with Pages when using ACF Pro: "Page Fields" field group|_"Page Content" Flexible Content field|__"Layout 1" layout|___"Title" Text field|___"Layout 1…
Pro
Post Titles and Post Content Tabs in Bricks

Post Titles and Post Content Tabs in Bricks

How to set up Nestable tabs with post titles as the tab menu, and post content and/or any other post-specific data as the tab content.
Categories:
Pro
Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

Related FAQs on Product pages Based on Product Category Taxonomy in Bricks

On product pages, we show all the FAQs associated with the current WooCommerce product's product categories.
Categories: