Home Forums Add-ons Repeater Field Get previous non-blank/empty value if current row is blank


Get previous non-blank/empty value if current row is blank

  • Hi there,
    I have a repeater field which has a row for each day of the month.

    In most cases the same value continues for several days or weeks. So it’s left blank, to indicate it is the same as the last non blank value.

    How can I output so if a cell is empty, to output the last non blank value???

  • A possible solution I got in mind is to create a separate field that holds the last non blank value that’s gets updated using update_field(). However, I don’t want this field to be editedable by admins.

  • Just keep the previous value in a variable and if the new one is blank then use the old one, something like this.

    if (have_rows('repeater')) {
      $prev_value = '';
      while (have_rows('repeater')) {
      $value = get_sub_field('sub_field');
      if ($value) {
        echo $value;
        $prev_value = $value;
      } else {
        echo $prev_value;
  • @John Huebner, thanks. That seems to work. However, this prev_value is needed by another page. So is it possible to save this prev_value in a field which is purely to make it available to other pages. It shouldn’t be editable (preferably not even seen but at least disable/un-editable).

  • I don’t think I really understand what you trying to do. If you’re going to use values from a repeater then you’ll need to loop through the repeater wherever it is that you’re showing it. What am I missing?

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

The topic ‘Get previous non-blank/empty value if current row is blank’ is closed to new replies.