Due to a massive import of posts from another cms into wordpress I have ended with thousands of posts without any category.
I need to add all those posts to the default category. I've seen this similar question asked before here: How to find all posts without category and assign the "Uncategorized"? but my little knowledge of the subject does not allow me to know how to apply the solution.
The solution was:
you can use
wp_set_post_categories()function. Get all of your posts(which you need to assign category) in an array and run a loop theough the array with
wp_set_post_categories( $post_ID, $post_categories, $append )passing needed parameter. It will assign the category to your posts.
Can someone explain to me how can I create the whole function and where and when do I run it?
I want to avoid the server to run out of memory for having so many posts to change.