Because $imgID
is an array of post objects. Instead of:
return $imgID;
You need:
return $imgID ? key( $imgID ) : 0;
Since get_children
returns an array of posts indexed by their ID, you can simply use key
to return the value of the first one.