Support

Account

Home Forums Add-ons Repeater Field Delete repeater`s sub_field after expired date Reply To: Delete repeater`s sub_field after expired date

  • Got it. But now it deletes all the rows, i think i write bad IF function or delete_row

    
      $args = array( 
        'post_type' => 'product', 
        'post_status' => 'publish',
        'posts_per_page'  => -1,
      );
    
      $listings = new WP_Query( $args );
      $count = 0;
      $today = date( 'Y-m-d' );
      global $product;
    
    // The Loop
    if ( $listings->have_posts() ) {
    	echo '<ul>';
    	while ( $listings->have_posts() ) {
    		$listings->the_post();
    		$count = 0;
        $repeater = get_field('pasirinkti_datas',$listings->ID);
        if (is_array($repeater)) {
          $count = count($repeater);
        }
    for ($row=$count; $row>0; $row--) {
      if (get_sub_field('keliones_datos',$listings->ID) <= $today ) {
        delete_row('pasirinkti_datas', $row,$listings->ID);
      }
    }
    echo '<li>' . get_the_title() .$count . '</li>';
    	}
    	echo '</ul>';
    } else {
    	// no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();