There is an anti-drainback valve inside the oil filter.
When you look at the base of the oil filter, this will be the black or orange flap that you see through the small holes around the outside part of the base, just inside the gasket.
This is supposed to keep the oil from draining out of the filter.
The orange one seems to have a better reputation for sealing the oil from flowing back into the motor than the black one, because the orange one is supposed to be silicone, whereas the black one is rubber.
The oil pump pushes the oil in through the small holes, pushes the flap you see through the holes......inward, and the oil flows through the media and back out through the big center hole.
When you shut the motor off, the flap is supposed to seal over the small holes, preventing the oil from draining out of the filter.
The idea is to keep oil inside the filter so that you get oil flow through the motor faster upon starting the engine up......without having to fill an empty oil filter first.
In short, in an ideal world, you should not come back to find an empy oil filter after a couple of hours.
In this photo, the orange "donut" would sit in the base plate, center hole lining up with the big center hole, and the curved part would be over the small holes.
The oil inside the filter would hold the flexible outer "flap" down over the small holes in the base plate.