Our mattress kept sliding towards one side of the frame, and while there are clamp on retainers on amazon, they only work for mattresses that are the exact width of the frame.
Ours isn't quite as wide as the frame, so I decided to make my own.
Example frame that this bar will fit on: https://www.amazon.com/gp/product/B0CW1MCCGY
They will extend in ~22mm from whatever they will rest against once installed. The slats on my frame have little plastic caps to prevent noise, so the 22mm starts at the edge of those caps. Even if they do not perfectly fit your mattress size, your mattress may have enough give/squish to compensate.
I printed mine with 3 0.4mm perimeters, using a PLA+ filament.
The author marked this model as their own original creation.