how to test for attached image

function has_image_attachment($post_id) {
    $args = array(
        'post_type' => 'attachment',
        'post_mime_type' => 'image/jpeg',
        'numberposts' => -1,
        'post_status' => null,
        'post_parent' => $post_id
    ); 

    $attachments = get_posts($args);

    if(is_array($attachments) && count($attachments) > 0) {
       //Has image attachments
       return true;
    } else {
       return false;
    }
}

Leave a Comment