Support

Account

Home Forums ACF PRO Count acf repeater with radio value only

Solved

Count acf repeater with radio value only

  • I’m wondering if its possible to get the count of a ACF repeater field only if its got a certain radio value ?

    Currently Im using

    $status = count( get_sub_field('sub_property_status') );

    In my template file to get the number of repeated rows in my custom post. Works fine.

    But in that custom post theres a radio button option with either “Draft Sub-Listing” or “Published Sub-Listing” to hide or show a curtain repeater row.

    Ideally I’d like to be able to count the rows that have the “Published Sub-Listing” only.

    Is this possible ?

  • Not easily. To do that you would need to loop over the repeater rows and get that sub field for each row and then add it to the count.

    
    // instead of $status = count( get_sub_field('sub_property_status') );
    $status = 0;
    if (have_rows('sub_property_status')) {
      while(have_rows('sub_property_status')) {
        the_row();
        if (get_sub_field('radio') == 'published value') {
          $status++;
        }
      }
    }
    
  • Hi John

    Thanks for taking the time to help. That’s done the trick 🙂

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Count acf repeater with radio value only’ is closed to new replies.