WordPress.org

Forums

Advanced Custom Fields
Adding Rows into a Repeater Programatically (CSV of Data) (1 post)

  1. DigitalOneOne
    Member
    Posted 9 months ago #

    As a note, I am just bulk importing into a single post.

    I currently have a CSV with over 500 values. I want to add a bunch of new rows with the data, and was wondering if there's a way to programmatically be able to do this?

    I created a Java program to handle the creation of code I need. See below.

    Here's my code:

    Main.java

    public static void main(String[] args) throws FileNotFoundException, IOException {
            CSVReader reader = new CSVReader(new FileReader("data.csv"));
            String [] nextLine;
            int count = 0;
            while ((nextLine = reader.readNext()) != null) {
                // nextLine[] is an array of values from the line
                Handler data = new Handler(nextLine, count);
                appendToFile(data, "results.txt");  // append data to end of a text file
                count++;
            }
        }

    Handler.java

    Private String lat, long;
    Private int count;
    
    public Handler(String[] line, int count) {
    	this.count = count;
    	if (line != null) {
    		for (int i = 0; i < line.length; i++) {
    			if (line[i] != null) {
    				switch(i) {
    					case 1: this.lat = line[0]; break;
    					case 2: this.long = line[1]; break;
    					default: break;
    				}
    			} else {
    				line[i] = "";
    			}
    		}
    	}
    }
    
    Public String toString() {
    	String repeater = "latlng_repeater"; //repeater field name
    	String value_lat = "latlng_repeater_item_lat"; // sub field name
    	String value_long = "latlng_repeater_item_long"; // sub field name
    
    	String repeater_field_key = "field_53cf18c22ee37; // repeater field key
    	String value_lat_field_key = "field_53cf19022ee3b"; // lat field key
    	String value_lat_field_key = "field_53d09ad6527ac"; // long field key
    
    	String post_id = "248";
    
    	String result = ""; // create code for insertion
    	return result;
    }

    https://wordpress.org/plugins/advanced-custom-fields/

Reply

You must log in to post.

About this Plugin

  • Advanced Custom Fields
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

  • RSS feed for this topic
  • Started 9 months ago by DigitalOneOne
  • This topic is not resolved
  • WordPress version: 3.9.1