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

  • 
     $args = array( 
        'post_type' => 'product', 
        'post_status' => 'publish',
        'posts_per_page'  => -1,
      );
    
      $listings = new WP_Query( $args );
      $count = 0;
      $today = date( 'Ymd' );
      global $product;
    
    // The Loop
    if ( $listings->have_posts() ) {
        while ( $listings->have_posts() ) {
            $listings->the_post();
            $count = 0;
        $repeater = get_field('pasirinkti_datas',$listings->ID);
        if (is_array($repeater)) {
          $count = count($repeater);
        }
    
        echo $count. '</br>';
        if( have_rows('pasirinkti_datas', $listings->ID) ):
          while( have_rows('pasirinkti_datas', $listings->ID) ) : the_row();
          
              $value = get_sub_field('keliones_datos', $listings->ID);
              if($value < $today) {
                  $row = get_row_index();
                  delete_row('pasirinkti_datas', $row, $listings->ID);
              }
          endwhile;
      endif;
        }
    } else {
        // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    

    This is the working code i guess?