I went around and around trying to figure how I could do this. I thought I would share incase someone is needing to do the same thing.
I had a CPT(Custom Content Type) that I was importing in based on an xml document. The xml document had image urls that I needed to not only download but also create soliloquy slider from. What is cool about WP Import All is that you can write custom code into certain hooks. Action reference here. I used “pmxi_gallery_image” hook that fired after every download of image. With the elements I constructed the array needed in meta data (“_sol_slider_data”) for each individual cpt.
Here is screenshot of how I configured the image download. I configured it to set the filename that way I know for sure there would not be any overlap across cpts.
The plugin versions when I did this.
WP All Import – Version 3.4.1
soliloquy – Version 2.3.4
Put this code in your functions.php. You will need to change the path. Which now when I look at this I should be able to get that from the id of attachment instead of hard coding it. Also make sure you change your config settings for slider. Best thing to do is create one how you want and then copy those settings out of the meta_data array. I used the DB but there is a plugin I found later that made it easier. (Debug Bar Post Meta).
/**
* WP Import All cpt soliloquy slider
*
* @param $pid – the ID of the post/page/Custom Post Type that was just created.
* @param $attid – the ID of the attachment
* @param $image_filepath – the full path to the file: C:\path\to\wordpress\wp-content\uploads\2010\05\filename.png
*
*/
add_action('pmxi_gallery_image', 'my_gallery_image', 10, 3);
function my_gallery_image($pid, $attid, $image_filepath) {
// your url and path to upload directory
$image_url_path = 'http://[your url]/wp-content/uploads/2014/09/' . basename($image_filepath);
$data = get_post_meta( $pid, '_sol_slider_data', true );
// if empty create array with default values. You will need to change these based on your slider options you want.
if ( empty( $data ) ) {
$data = array(
'id' => $pid,
'config' => array(),
'slider' => array(),
'status' => 'active'
);
$data['config']['type'] = 'default';
$data['config']['slider_size'] = 'default';
$data['config']['slider_theme'] = 'metro';
$data['config']['slider_width'] = '656';
$data['config']['slider_height'] = '300';
$data['config']['position'] = 'center';
$data['config']['transition'] = 'fade';
$data['config']['duration'] = '5000';
$data['config']['speed'] = '400';
$data['config']['gutter'] = '20';
$data['config']['auto'] = '1';
$data['config']['smooth'] = '1';
$data['config']['arrows'] = '1';
$data['config']['control'] = '1';
$data['config']['pauseplay'] = '0';
$data['config']['hover'] = '0';
$data['config']['slider'] = '1';
$data['config']['mobile'] = '1';
$data['config']['mobile_width'] = '600';
$data['config']['mobile_height'] = '200';
$data['config']['keyboard'] = '1';
$data['config']['css'] = '1';
$data['config']['loop'] = '1';
$data['config']['random'] = '0';
$data['config']['delay'] = '0';
$data['config']['start'] = '0';
$data['config']['classes'] = '';
$data['config']['title'] = '';
$data['config']['slug'] = '';
}
$data['slider'][$attid] = array(
'status' => 'active',
'id' => $attid,
'src' => $image_url_path,
'title' => get_the_title( $attid ),
'link' => '',
'linktab' => '',
'alt' => get_the_title( $attid ),
'caption' => '',
'filter' => '',
'type' => 'image'
);
update_post_meta($pid, '_sol_slider_data', $data);
}
I know I am not great at articulating the steps I took. Thats why I am going to start writing some blogs to help me and hopefully you. Let me know if you have questions and I can try to help.