What your are doing is that you are looping over an array of post objects.
The get_posts()
function returns objects, not ID’s.
So what you will have to do is either use
$post_id->ID
or
setup_postdata( $post_id )
and then use get_the_ID()
.
Might wanna rename $post_id
to $post_object
to avoid confusion.