Home Forums Backend Issues (wp-admin) Import Custom Posts via CSV Reply To: Import Custom Posts via CSV

  • Hi!

    With the plugin Really Simple Csv Import, that is free and open source (, you can import Csv fields like “name a, name b, name c” as repeater fields or <select> elements. The author made specific hooks (filters) for this goal and they are well documented here.

    For example, taking advantage of the “really_simple_csv_importer_save_meta filter” I managed to import, from a Csv, a field written like “author a, author b, author c” as a ACF repeater in WP, with the following code of mine:

    add_filter('really_simple_csv_importer_save_meta', function($meta, $post, $is_update) {
         if (strpos($value, ',') !== false) { // if there is a "," in the string...
    	            $_value = preg_split("/,+/", $value); // "author a, author b, author c" pattern is converted in an array
    	            $rows = count($_value); // return the number of the elements in array
    	            $meta[$key] = $rows; // in ACF scheme, this is the meta_key for the number of rows, ie: "meta_key : authors, meta_value: 2"
                	// the loop creates each single row, in the form required by ACF: "meta_key: authors_0_author, meta_value: Mario Rossi" 
    	            for ($i=0; $i<$rows; $i++) {
    		            $plural = 'authors';
    		            $addition_sign = '_';
    		            $singular = 'author';
    		            $meta[$plural.$addition_sign.$i.$addition_sign.$singular] = $_value[$i]; // ie:  $meta['authors_0_author'] = $_value[0];
    	            } // end "for"
    } // end if
    else { // when the repeater has only one value...
    	        	 $i = 0;
    	        	 $plural = 'authors';
    		         $addition_sign = '_';
    		         $singular = 'author';
    	        	 $meta[$key] = 1;
    	        	 $meta[$plural.$addition_sign.$i.$addition_sign.$singular] = $value;
            	} // end else