// Store any post ids
$added_properties[] = $id;
// Add property meta data
add_post_meta($id, "property_id", $property_id , true);
add_post_meta($id, "property_price", $priceVal , true);
add_post_meta($id, "bedrooms", $bedrooms , true);
add_post_meta($id, "livingrooms", $receptions , true);
add_post_meta($id, "bathrooms", $bathrooms , true);
add_post_meta($id, "gardens", $gardens , true);
add_post_meta($id, "garages", $garages , true);
update_post_meta($id, "type", $type , true);
// Set taxonmony term
wp_set_object_terms( $id, 7, "property_type");
// Store all media data in array
$images = array();
$epc = array();
foreach ($prop_xml->files->file as $file ) {
// Get file type id
$type = $file->attributes()->type;
$file_id = $file->attributes()->id;
// Get file url
$url = $file->url;
$post_id = $id;
$tmp = download_url( $url );
$desc = $title;
$file_array = array();
// Set variables for storage
// fix file filename for query strings
preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png|pdf)/i', $url, $matches);
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
// If error storing temporarily, unlink
if ( is_wp_error( $tmp ) ) {
echo 'tmp file error<br>';
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$img_id = media_handle_sideload( $file_array, $post_id, $desc );
// If error storing permanently, unlink
if ( is_wp_error($img_id) ) {
echo ' file error<br>';
@unlink($file_array['tmp_name']);
return $img_id;
}
$src = wp_get_attachment_url( $img_id );
if($file_id == 0){
$image_path_large_id = $img_id;
}
switch ($type) {
case '0':
echo 'its an image\n';
$images[] = $img_id;
break;
case '9':
$epc[] = $img_id;
default:
break;
}
}
// Save meta image data
if(!empty($images))
update_post_meta($id,'property_secondry_images_id', $images );
unset($images);
if(!empty($epc))
update_post_meta($id,'epc_media', $epc);
unset($epc);
if(!empty($image_path_large_id ))
update_post_meta($id,'property_main_image_id', $image_path_large_id );
unset($image_path_large_id );