get_children – wp_get_attachment_image

You could Limit the output to 1 like this but this is not a solution, only a workaround:

    $args = array('post_parent'    => get_the_ID(),
          'numberposts' => 1, 
          'order'          =>  'ASC',
          'post_type'      => 'attachment',
          'post_mime_type' => 'image'
     );

$images = get_children( $args );
if ($images) 
{
    foreach ($images as $image) 
    {
        echo wp_get_attachment_image($image->ID, 'full');
    }
}

Have you the Premission to delete on your server?

Leave a Comment