• Hi there,

    I’ve been finding this plugin extremely useful the last while but wanted to make a customisation and I’m not entirely sure how to go about it.

    I need to prevent duplicate posts from being imported.

    In my CSV I will always have a unique ID as one of the custom fields. I wanted to check this unique ID against all posts currently in the WordPress database.

    I’m fairly sure for the PHP code I’ll just need to extract the CSV custom field ID, and then create an array of the matching custom field value of all current posts, then I can check if there’s a match using in_array. If it matches then I want to skip to the next line in the CSV and repeat that check.

    I’m guessing it would go somewhere in here:

    foreach ($csv->connect() as $csv_data) {
    	if ($post_id = $this->create_post($csv_data, $options)) {
    		$imported++;
    		$comments += $this->add_comments($post_id, $csv_data);
    		$this->create_custom_fields($post_id, $csv_data);
    	} else {
    		$skipped++;
    	}
    }

    but am not entirely sure. Can you give any pointers on how I might achieve this?

    Cheers,
    Alex

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor dvkob

    (@dvkob)

    alexleonard: Your approach sounds good. You can put that logic either in the loop you posted or inside the create_post() method. query_posts() function will probably be of help.

    Thread Starter alexleonard

    (@alexleonard)

    Hey dvkob,

    Thanks for the quick response. Good to know my thinking is heading in the right direction.

    Although it’s looking like I may actually, due to some quite strange requirements, have to allow duplicates to be imported, but not display them in my loops if two separate required unique fields are not met. Quite confusing but I’m sure I’ll get there in the end!

    Thanks again,
    Alex

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: CSV Importer] Making custom changes’ is closed to new replies.