In this study, polymeric ionic liquids (PILs) modified magnetic nanoparticles were used to extract four aflatoxins (AFs) from wheat samples, providing a convenient and cost-effective sample preparation technique for AFs detection in the complex food matrix. The extraction parameters were optimized in terms of the amount of adsorbent, adsorption time, type and volume of desorption solvent, desorption time, and salt addition. The results showed that the proposed method had high sensitivity, good repeatability, and wide linear range. The limits of detection (S/N=3) of four AFs were 0.05-0.41 μg kg