Condition inside ACF repeater?

Hello,

Pretty sure it is not possible as I have tried almost everything.

Let say I have an ACF repeater define as an “Option Page” ( ACF | Options Page ).

And inside that ACF repeater, I have another ACF repeater like this:

Care_1

  • product_1 - price_1
  • product_2 - price_2
  • product_3 - price_3

Care_2

  • product_4 - price_4
  • product_5 - price_5
  • product_6 - price_6

What I want is when I’m on a Post named “Care_1”, that only Care_1 and sub_field would display.

I know the correct way of doing this would be to add the ACF repeater directly to each Post page Care_1 and Care_2 but as my client is not really tech friendly, I wanted to centralise all the price option, so the idea of the “Option Page” is that he can change all the Prices from one interface rather than going to every single post page where the care are describe.

On the backend it looks like this:

This is my Bricks Structure:

So the idea would be to have the first ACF repeater, then a condition that if the page title is equal to Care_1, that only the line Care_1 would be display and not Care_2.

This is my condition function:

function nh_is_prix_categorie_match_page_title() {
    if ( have_rows( 'repeater_tarifs', 'option' ) ) {
        $current_page_title = get_the_title(); // Get the current page title
        while ( have_rows( 'repeater_tarifs', 'option' ) ) : the_row();
            $prix_categorie = get_sub_field( 'prix_categorie' );
            if ( $prix_categorie === $current_page_title ) {
                return true; // If a match is found, return true
            }
        endwhile;
    }
    return false; // If no match is found or there are no rows, return false
}

But it doesn’t work, the div get display for Care_1 and Care_3 on all the Care_[1-4] pages.

So it looks like “conditions” are not working inside ACF repeater, maybe it’s just not supposed to work, or it’s a bug, or I’m doing something wrong ? I don’t know.

Thanks.

Nicolas.

Hi! Did you ever figure out a solution?

Hello,

Yes, I use the “Loop Item Number” from Bricks Extra:

Not exactly what I wanted but it does the job for me.

BricksForge has the same idea with “Loop Index” :slight_smile:

Regards,

Nicolas.