you can use the default gallery behavior to your need
Insert a gallery in tour post, it will create a shortcode like
[gallery ids="12,45,67,34"]
override the default gallery shortcode function to not display it in your post
remove_shortcode( 'gallery', 'gallery_shortcode' ); add_shortcode( 'gallery', 'my_gallery'); function my_gallery(){ return ''; }
retrieve an array of images ids
$post_content = get_the_content(); preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); if($ids){ $array_id = explode(",", $ids[1]); }