sql如下:
INSERT INTO wp_term_relationships (object_id, term_taxonomy_id, term_order) SELECT p.ID, (SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id = 129 AND taxonomy = 'category'), 0 FROM wp_posts p LEFT JOIN wp_term_relationships tr ON p.ID = tr.object_id AND tr.term_taxonomy_id != 0 WHERE p.post_type = 'post' AND p.post_status = 'publish' AND tr.object_id IS NULL;
其中
term_id = 129
为指定分类ID