modify the code with wp_set_object_terms in functions.php wordpress
This piece of code works for me, but I have more than 10,000 posts in post types on my website, and by calling posts_per_page => -1
The loading speed of the site is very low and the RAM and CPU are heavily involved and become 100%.
I want to optimize this code so that there is no need to call posts_per_page => -1 and load all the posts in Admin Ajax.