Since i've thousands of articles the bulk edit is impossible. It will require too much time and with 999 articles a time WordPress will already crash.
So i thought about using a simple db query but i'm not sure how to build it.
How can i set a specific category for every post containing a specific word?
For example i want to put into the "business" category every article containing the "business" word.
What kind of query should i use?
I tried something i found here but without any success. The answer are always not clear or suggesting to use the bulk edit function that is something i can't use.
Using WP CLI commands is the most performant way of doing this: it's high performant, and uses WordPress functions (mentioned by GeorgeP).
Use wp post list
to get the list of posts, and then wp post term add
to set the term on the posts.
Here's a Bash script I found that may work (untested):
for post in $(wp post list --s=business --format=ids)
do
wp post term add $post category 'category_name'
done
Source: https://www.presslabs.com/code/wp-cli-guide-wp-term/