Hemorrhoids are not a sexually transmitted infection, nor are they contagious. Sex with someone who has hemorrhoids does not put you at risk for getting them. Hemorrhoids are typically caused by constant or repeated pressure to the anal or rectal veins.
Hemorrhoids are fairly common, and while described as not serious, they can cause pain and bleeding. A doctor or nurse practitioner can diagnose hemorrhoids by asking about past health and perhaps examining the area. A clinician may be able to help with treatment or pain management.
If you experience hemorrhoids and engage in anal sex, ask your doctor for STI testing. During periods when you notice bleeding, you may want to consider using a condom to avoid exposing your partner to blood that might be present, and use lube to reduce the stress to the area. Another harm reduction option would be to engage in other types of sex (avoiding anal sex) while hemorrhoids are healing.
Hope this is helpful!