How do you get UTI’s

I peed after sex and it’s been a few days since I had sex. But one thing I did do was last night I didn’t shower. Could that be it?