wp_insert_attachment sets all what I need, but you have to add as the first argument an array. It isn't necessery in my case, because my attachment has been already loaded to the DB. All I have to do is setting post_porent. If you want to dettach, you have to set post_parent to 0 (zero).
But as I wrote in the second post - I can set only one parent of the attachment since the type of post_parent field is BIGINT. This way I answered by myself for my question from the first post and I stopped searching a proper function, but it's very simple, even if you are to set it with
My second question is if you know a good way to set many parents of one attachment. I think the best way would be setting custom_fields. You just has to use:
add_post_meta($post_id, $meta_key, $meta_value, $unique);
where the last optional argument $unique with default
false allows you to set many meta values for one meta key. For instance:
attached_image => image1.jpg
attached_image => image2.jpg
Then you can simply get it with:
IMHO it's the simplest way to set many images to many posts.
I'd just ask you to confirm it or tell me some smarter way if you know any.
wp_insert_attachment is good when you want to post (
$_POST) your form.
media_sideload_image($file, $post_id, $desc);, where file is simply URL, because I load images from another server. It's a very convient function.