I have attachment id, but can't find way to get post id by this attachment id. I can loop all posts and find it, but maybe exists easy way get it. Does anyone know a similar function?
get_post_ancestors can give you the ID of the object an attachment is associated with:
$attachment_id = 42; $parent = get_post_ancestors( $attachment_id ); echo $parent; // $parent will be an array