30th Sep '25
/
0 comments

ACF Group Sub Field Values from Matching Post Term

In Bricks Reddit, a user asks:

Hi guys!

Maybe I'm completely wrong with this approach, but I would like your opinion on this...

So what I'm trying to do here is where you have a post with a tag that can get data through an ACF option page based on that tag (same name).

Now this is a very very simple example of what I'm trying to achieve through a query loop.

Previously I've been trying to achieve this with Elementor and it was just plain horrible to do this with just duplicating containers and setting conditions based on the tag/post title/parent, which is not very efficient. Since I moved to Bricks, I know this is possible, but the options are sometimes mind-boggling to me, especially with the queries.

As I said, this is a very simple example. Instead of having all the data in a post, I want to manage this more centralised through a ACF option page where I can edit the data from there and is then dynamically loaded based on a tag. The country tag is used for something else entirely, that's why it's there.

Many, many, many thanks if you guys can route me to get this to work :) It's really appreciated!

Note: The website itself is just in English. It's just "some" landing pages that need to be translated in this way so it's easy to maintain on the long-run.

Again... any help is appreciated!!

Let's break this down and set up the scenario practically.

First, there's a Language taxonomy for posts (could be standard posts or a CPT posts) with these sample terms:

Sample posts with languages assigned:

Based on the graphic in the question, we are assuming that a post will have at most 1 language assigned to it. We shall code in such a way that even if there are multiple, the first one will be considered.

Then there's a ACF options page.

with this field group:

Each language has a Group field of its own and the sub field names are the same inside each.

Site settings fields populated:

The objective is (in single post template) to

  • check if the current post has a Location term set (Ex.: Spanish)
  • check if this Location term's slug (Ex.: spanish) has a matching name in the site settings field group (Ex.: https://sri.smmall.cloud/MTc1OTIxODYwMTMwMA)
  • check if this group has data i.e., field value (Ex.: https://sri.smmall.cloud/MTc1OTIxODY4MTI0MA)
  • create a custom function that takes a specific sub field name (Ex.: content_title) and returns the matching field value array from ACF settings page based on post's language taxonomy term
  • create another custom function that returns true or false depending on whether the current post has at least one language taxonomy term with a corresponding ACF field group on the settings page

and use the functions to conditionally output the data in single post template.

This Pro tutorial provides the code for this and while it is generic and can be used in any WordPress site including Elementor, we shall use Bricks theme for the implementation.

Step 1

Set up the location taxonomy, add a few terms, create a ACF options page, add a field group having Group type of fields with the same names as the taxonomy terms, add (the same) desired sub fields in each group, and add a few sample posts with locations set.

Step 2

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..

Pro
Month and Day Condition in Bricks

Month and Day Condition in Bricks

This Pro tutorial shows how we can define a custom function that takes in a month in the three-letter format (like Dec) and a day…
Categories:
How to add a “Sold Out” badge for out of stock products in Bricks

How to add a “Sold Out” badge for out of stock products in Bricks

Looking to add a "Sold Out" badge for products in the Shop page for WooCommerce products that are out of stock when using Bricks' Products…
Checking for Post Type in Bricks

Checking for Post Type in Bricks

A way to output elements conditionally based on the current post type in the loop in Bricks.
Categories:
Pro
Conditionally Hiding Bricks Filters based on Select Filter Value

Conditionally Hiding Bricks Filters based on Select Filter Value

How show or hide Bricks' filter based on the selection made by another filter.
Categories:
Tags:
Pro
How to Update Custom Fields with Default Values For Existing Posts when using ACF

How to Update Custom Fields with Default Values For Existing Posts when using ACF

Let's take a scenario where there are 10 Pages in a WordPress site. You proceed to create a Text-type of custom field called, say, "Custom…
Categories:
Tags:
Pro
ACF Flexible Content Field – Layout Labels and Sub Field Labels

ACF Flexible Content Field – Layout Labels and Sub Field Labels

How to output the text of layout labels and/or sub field labels using the Flexible Content field of ACF Pro.
Categories:
ACF Checkbox Items with Custom SVG Bullets in Bricks

ACF Checkbox Items with Custom SVG Bullets in Bricks

We walk through outputting list items with SVG icons based on the choice of a ACF Checkbox field.
Categories:
Tags:
Pro
ACF Taxonomy Field Value in Single Posts

ACF Taxonomy Field Value in Single Posts

Consider this scenario: CPT: Movie Movie CPT Taxonomy: Movie Genre Movie Genre Taxonomy's field: Genre Color Each movie will have only genre set. The requirement…
Categories:
Tags: