Home Forums Add-ons Repeater Field Output repeater field as table Reply To: Output repeater field as table

  • In order to display the repeater by category you would first need to sort the repeater by a sub field.

    There is some documentation here on using array_multisort() (PHP Doc

    If you know how to do so you might also want to look into using usort() which is the method I prefer Sorry, I don’t have time at the moment to give you an example, but I did post an example of it here this can probably be used in an acf/load_value filter like the ACF example.

    Once you have the repeater sorted then you need to loop over the repeater, keep track of the current category, previous category and then start a new output when the category changes.

    $prev_category = '';
    $table_started = false;
    while (have_rows('product')) {
      $this_category = get_sub_field('product_category');
      if ($this_category != $prev_category) {
        // category switch
        if ($table_started) {
          // close previous table elements
          $table_started = false;
        // output heading for new category
      if (!$table_started) {
        // output opening elements of new table
        $table_started = true;
      // output table row for product