Ok so I'm using an ajax function to display all images that are included on the page.

 function post_love_add_love() {

        $post->ID = $_REQUEST['post_id'];
        $args = array(
        'post_parent' => $post->ID,
        'post_type'   => 'attachment', 
        'post_mime_type' => 'image',
        'numberposts' => -1,
        'post_status' => 'inherit' 
    $children = get_children( $args );

    echo $post->ID;

    foreach ( (array) $children as $attachment_id => $attachment ) {
        echo wp_get_attachment_link( $attachment_id );


This mostly works as expected. When I add 3 images to a page, this function will re-display those 3 images. The problem comes in when I delete 1 of those images from the page (on the admin side). This function continues to display all 3 pictures when it should only be displaying the 2.

I recognize that it's doing this because the deleted images must still be attached to the post even though they were deleted on the admin side. So my question is how can I filter out the deleted posts in my arguments to the get_children function?


  • Your images are in a custom field or in the wordpress editor? anyway you need to detach the image from her parent – Shibi Feb 1 '17 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.