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

Related Tutorials..

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
ACF Font Awesome Field in Bricks

ACF Font Awesome Field in Bricks

We walk through using the Advanced Custom Fields: Font Awesome Field plugin for showing Font Awesome icons.
Categories:
Tags:
Pro
ACF Relationship: Show all other events related to the artists of the current event

ACF Relationship: Show all other events related to the artists of the current event

How all other events related to the artists of the current event can be output in a Bricks query loop.
Categories:
Pro
Meta Box/ACF Images Staggered Grid Gallery in Bricks

Meta Box/ACF Images Staggered Grid Gallery in Bricks

Showing images from two Gallery-type of ACF or Image Advanced-type of Meta Box fields in a staggered grid layout.
Pro
Upcoming Events Grouped by ‘Month Year’ in Bricks

Upcoming Events Grouped by ‘Month Year’ in Bricks

A custom query loop type for showing future events based on a date custom field using three nested query loops.
Pro
Limit Bricks Users Query to Current Post’s User-type ACF Field Value

Limit Bricks Users Query to Current Post’s User-type ACF Field Value

Consider this scenario with ACF: "John Briley" user: "Gandhi" movie: The requirement is to show John Briley as the author when Gandhi movie item is…
Categories: