Fertilizers such as phosphate are removed through addition of another chemical, usually iron. The substances than become solid precipitates, that can be filtered from the water.
The removal of ammonium and nitrates is a bit more complicated; it is a purification process that takes both aerobic and anaerobic conversion to remove them.