Translation - Μετάφραση
Resources, Technical Assistance and Technology News => Translator resources => Tips on Using Computers => Topic started by: spiros on 01 Jan, 2021, 17:19:11
-
Batch add categories in WordPress with SQL query via PhpMyAdmin
Wordpress: SQL query to add or remove categories on multiple posts (https://www.ryadel.com/en/wordpress-sql-query-to-add-or-remove-categories-on-multiple-posts/)
What worked for me was:
INSERT INTO `wp_term_relationships` (object_id, term_taxonomy_id, term_order)
SELECT ID, 42, 0 FROM `wp_posts` p
WHERE p.post_type = 'post' AND p.ID NOT IN
(SELECT object_id FROM wp_term_relationships tr3
WHERE tr3.term_taxonomy_id = 42);
42 is the category number. And then I had to go to wp_term_taxonomy and change the number for the specific category to the one displayed on wp_term_relationships. Using MariaDB 10.3.