Relate Content to a Group feature when creating a node outside a group
Well, if I understand your problem correctly, you could just add an entity_reference field to your node type 'userpost' via admin toolbar. Go to Structure->Content types->userpost->Manage fields->Add field->Choose Reference (other)->Select Group and set cardinality to whatever you want.

This would allow you to add group references when you create a new node of content type userpost

Update
What I described adds a reference from a node to one or multiple group(s) via a new field, it does NOT add this node as a group-content to your group(s). It depends what you are trying to achieve? If you want to add your node as a group-content and you want to do this via the node creation form, you need one more extra step. You can implement a hook_ENTITY_TYPE_insert(). From there get the group(s) that you entered to your node field (from $node), $groups = $node-&gt;get('field_groups') and add the $node as group_content to each group, similar as done in the answer you linked.