[SOLVED] to conditionally set background color using an ACF Group field color property?

Thanks

Can you post a screen shot from within the Bricks builder?

I want to see how you built up the loops and all the elements inside the loop in Bricks.

Thanks

Patric

Hi Monia

You can also target a repeater or even a subrepeater. No problem.

I also have a query loop with a repeater and a subrepeater. I use a Div for the subrepeater:

Attribute

The element ID of the subrepeater Div is ‘jiipdu’:

Attribute2

In the filter code, I can now target this Div via the element ID directly:

if ( $element->id === 'jiipdu' ) {

For example, I can now make the background of every item inside this subrepeater Div blue if I wan to:

$attributes['class'][] = 'background_blue';

I can also target the Text element inside the subrepeater Div if I want. I just have to change the element ID:

Attribute3

if ( $element->id === 'drjgcw' ) {

So it all comes down to just finding the right element ID, which is not so difficult if you remember to find the element ID inside the Bricks builder directly.

I take it from your screen-shot that you are using Jet-Engine for custom fields. In my code, this line

if(get_field('property_label_text') == "Hot Deal") {

works specifically for ACF fields (get_field). I don’t have Jet-Engine. Is the Jet-Engine php code also “get_field”?

Cheers

Patric

Hello Patric,

As mizzinc said, “Patric delivering the goods.” :slight_smile: To address your latest message, I believe JetEngine functions the same based off my testing of both ACF and JetEngine. I’m hoping either plugin can provide me a solution.haha

Now, after scouring the forums, I believe this issue lies on how query loops output repeaters. Despite repeater items containing a post object id field, the item itself is not a post and thus cannot detect the custom field attached to it. But you would know more than me if that is indeed the case.

With that said, there maybe a solution to working with repeaters by applying your solution in a slightly different way.

  1. Create an additional ACF field with the select field type (values = Hot Deal, Sold, New etc.) in the repeater.
  2. Create a custom attribute for your block or div within the query loop (ex. name = custom ).
  3. Set the attribute dynamic value to the newly created repeater field.
  4. Elements will now display the attribute and field value.

Issues

  1. You cannot “name” your attribute the same as your custom field included in the post (property_label_text). Otherwise, it will pull the value from the current post and not the repeater. (As long as you avoid this, you’re good to go).
  2. I have no idea how to callback a post featured image based off a repeater “post object ID” field in a query loop. Setting the dynamic value {acf_asc_mats_asc_lvl} from the repeater field to a bricks image widget will not callback the featured image.

The repeater outputs the correct post id but it’s just a matter of figuring out how to callback the featured image. If I could get the image to display and how to style the new attribute then repeaters would become especially versatile in Bricks.

Please let me know if you have any suggestions Patric. :slight_smile:

Bricks Builder - Structure

Custom Attribute

To call back the featured image, what is output if you put an image element into the repeater or subrepeater and enter

{featured_image}

in the dynamic field of the image element?

Rep7

Cheers

Patric

@monia

Now I am not sure anymore that I understand what you are trying to achieve.

The featured image belongs to a post or a page and there is always only one per post or page (for example the foto of a dish in a cooking recipe post)

The ACF repeater is a repeating structure that can be used to add repeating content to a post or page. For example all the required cooking steps together with a foto in a food recipe.

The ACF repeater is usually connected to a post or page.

So it is not clear to me why you are trying to use a repeater to show the featured image.

The normal way would be you make a standard query loop over posts, then within that query loop you add an image element to show the featured image and you add a repeater loop to show the content of the repeater (for example the recipe cooking steps with a foto of the cooking step) assigned to the post that is currently looped over.

Cheers

Patric

Hello Patric,

Thanks for writing back and I’ll try to explain. And yes you are correct in how everything works but I want to make the list dynamic. For example:

Let’s say I have a CPT called “ingredients”. Within this cpt we have four posts (all with a featured image) which are:

  • Eggs
  • Flour
  • Tomatoes
  • Olive Oil

Now, let’s jumpt to our other CPT called “Recipes” and this is where the repeater is located.
The repeater has two fields which are: Ingredient (Post Object ID) and Quantity (Number field).

On the frontend, the repeater is located in the Recipe single post template which displays the list of ingredents you need. You mentioned just using a static image in the repeater (which would work).
So, why do it this way?

If I had 3,000 recipe posts that contained the ingredient “Tomato”, I could change the featured image on the tomato post and it would display the change on all three thousand posts. Otherwise, I would have to go by hand and change the static image in the repeater. Of couse this is an example, and this use case comes into play when creating entertainment type of websites.

I hope this clears things up. :slight_smile:

Since this has become off-topic, I will copy this message to my new thread you responded to for context. Thanks for all your help.