Tạo Trường(field) repeater trong plugin Advanced Custom Field Pro(ACF)

Tạo hàm nhập liệu từ file CSV 

Trong file functions.php bạn thêm đoạn code sau:

add_action( 'save_post', 'tmdev_import_data_from_csv', 10, 3 );
function tmdev_import_data_from_csv( $post_id, $post, $update ){
    if( $post->post_type != 'your_custom_post_type' ) return;

    if( get_field('data_results_by_provinces_vn', $post_id) ) {
      // load csv with SERVER PATH instead of URL
      $csv = get_attached_file(get_field('data_results_by_provinces_vn', $post_id)['id']);

      if( ($handle = fopen($csv, "r") ) !== FALSE) {
        $count = 0;
        while(($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $count++;
            update_sub_field(array('results_by_provinces_vn', $count, 'stt'), $data[0], $post_id );
            update_sub_field(array('results_by_provinces_vn', $count, 'provinces_of_vn'), $data[1], $post_id );
            update_sub_field(array('results_by_provinces_vn', $count, 'registered_members'), $data[2], $post_id );
            update_sub_field(array('results_by_provinces_vn', $count, 'distance'), $data[3], $post_id );
        }
        update_post_meta( $post_id, 'results_by_provinces_vn', $count );
        fclose($handle);
      }
    }
}

 

Bài viết liên quan

post-no-image

Chia sẻ một số thư viện loading css đẹp

giai-phap-chinh-css-khong-bi-luu-cache-trinh-duyet

Giải pháp tốt khi chỉnh sửa css mà không sợ bị lưu cache trình duyệt

post-no-image

Một số css tùy biến thẻ input type: select, number

post-no-image

Tắt lazyload cho một số hình ảnh

post-no-image

Tuỳ biến layout YITH WooCommerce Wishlist

post-no-image

Một số hook hoặc filter thường sử dụng trong plugin WPML