Support

Account

Home Forums Add-ons Repeater Field Delete repeater fields when is null or empty programatically?

Helping

Delete repeater fields when is null or empty programatically?

  • I have a function that remove the value of repeater field when this value is old date, but not deleting the row, this still show but empty. How I can remove the rows when the value is null or empty?

    This is the estructure of my custom fields:

    
    r1 (repeater)
    - t1 (text)
    - t2 (text)
    - r2 (repeater)
    -- d1 (date)
    

    This is my function:

    $fields = get_fields();
    foreach($fields as $key_1=>$value_1) {
      $parent_i = 1;
      foreach($value_1 as $key_2=>$value_2) {
        foreach($value_2 as $key_3=>$value_3) {
          $child_i = 1;
          if ($key_3 == 'movies') {
            foreach($value_3 as $key_4=>$value_4) {
              foreach($value_4 as $key_5=>$value_5) {
                if( $value_5 < $time_now) {
                  delete_sub_field( array('cinema', $parent_i, 'movies', $child_i, 'date') );
                } elseif( $value_5 > $time_now) {
                  update_sub_field( array('cinema', $parent_i, 'movies', $child_i, 'date'), $value_5 );
                }
                $child_i++;
              }
            }
          }
        }
        $parent_i++;
      }
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Delete repeater fields when is null or empty programatically?’ is closed to new replies.