Heavy metals in the swine wastewater not only influence phosphorus (P) recovery through struvite but also incorporate with struvite, posing a potential threat to its safe application. We investigated the incorporation of copper (Cu) and zinc (Zn) with struvite in response to several factors (pH, HCO3-, initial metals concentration, and Cu/Zn ratio) by batch experiments and Response Surface Methodology, and to clarify their possible adsorption mechanisms using Minteq and X-ray photoelectron spectroscopy analysis. The results proposed that higher pH and HCO3- in the wastewater both promoted struvite formation and greatly inhibited the adsorption of such heavy metals on the struvite. The performance of Cu and Zn varied under various conditions, meaning their different adsorption mechanisms. Compared with Cu, Zn is more prone to adsorb onto struvite due to the lower stability of Zn(NH3)(x)(2+) and the supersaturation ratio (Sa) of Zn-containing precipitation is greater than that of struvite. The removal of Cu was more susceptible to the interaction of pH with other variables, while that of Zn more determined by the interaction of HCO3- concentration with other factors. ANN provides a range of parameter sets for different requirements of metal adsorption rate, thus maximizing P recovery and suppressing heavy metal residues on struvite based on the Artificial Neural Network. The driving forces for heavy metal-struvite interactions include surface adsorption, complexation, precipitation, immensely associated with the initial metal concentration, wastewater properties, and running parameters. The results will provide theoretical progress and complete parameter sets for recovering struvite from actual wastewater.