Skip to content

Instantly share code, notes, and snippets.

@hissy
Created February 25, 2015 14:01
Show Gist options
  • Select an option

  • Save hissy/0973a6a9977129a6ebd0 to your computer and use it in GitHub Desktop.

Select an option

Save hissy/0973a6a9977129a6ebd0 to your computer and use it in GitHub Desktop.
[Really Simple CSV Importer] Example: import image from url to custom field
<?php
/*
Plugin Name: Get Remote Image to Custom Field
*/
add_filter('really_simple_csv_importer_post_saved', function($post)
{
if (is_object($post)) {
// Get the meta data of which key is "image"
$image = $post->image;
// Create a instance of helper class
$h = RSCSV_Import_Post_Helper::getByID($post->ID);
// Get the remote image data
$file = $h->remoteGet($image);
// Then, attach it
$attachment_id = $h->setAttachment($file);
// Finally, replace the original data with the attachment id
$h->setMeta( array( 'image' => $attachment_id ) );
}
});
@hissy

hissy commented Feb 25, 2015

Copy link
Copy Markdown
Author
"post_title","post_type","image"
"Get remote image test","post","https://s.w.org/about/images/logos/wordpress-logo-stacked-rgb.png"

@gera3d

gera3d commented Aug 17, 2017

Copy link
Copy Markdown

Is there a way to import an image with the meta info attached?

@gera3d

gera3d commented Aug 17, 2017

Copy link
Copy Markdown

Found the answer.
_wp_attachment_image_alt

@neutronixx

Copy link
Copy Markdown

Hollo, how is the installation? and usage?

@hissy

hissy commented Nov 11, 2019

Copy link
Copy Markdown
Author

@neutronixx Please follow the normal plugin installation process. This plugin is made for developers. If you can't understand what this plugin does or you are not familiar with WordPress's filter system, please try to find another plugin.

@erikdemarco

Copy link
Copy Markdown

Is there any way to import multiple images?

@hissy

hissy commented Apr 9, 2022

Copy link
Copy Markdown
Author

You can do it, but I don't provide sample codes for all cases. Please try it by yourself.

@erikdemarco

Copy link
Copy Markdown

@hissy How to post a bug?

If post category contains comma it will be treated as new category.

For example:
Category 1: Bike, Motorcycle, Other 2 Wheel Vehicle
Category 2: Vehicle Accessory

I have tried woocommerce way of importing like:
Bike, Motorcycle, Other 2 Wheel Vehicle, Vehicle Accessory
Bike, Motorcycle, Other 2 Wheel Vehicle, Vehicle Accessory

It will always end up like:
Category 1: Bike
Category 2: Motorcycle
Category 3: Other 2 Wheel Vehicle
Category 4: Vehicle Accessory

How to fix this?

@hissy

hissy commented May 8, 2022

Copy link
Copy Markdown
Author

@erikdemarco You can make a support thread on the official forum: https://wordpress.org/support/plugin/really-simple-csv-importer/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment