The function below returns all the images attached to the post, however, if I delete the image inserted into the content, it still returns in the function, because the media is still as attached to the post.
So, how do I really bring only the images inserted in the content of the post?
<?php
$args = array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_mime_type' => 'image',
'post_parent' => $post->ID,
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, false );
echo '<hr>';
echo '<br>';
}
}
?>