I have a thousand posts and all them don't have category. So, Do you know how to associate category with all posts by using sql query ? Thank you !
Asked
Active
Viewed 4,281 times
3 Answers
2
First you need to know the id of you category you want your posts to be associated with. Look in the table wp_terms column term_id.
INSERT INTO wp_term_relationships (object_id, term_taxonomy_id)
SELECT ID, 'TERM_ID' FROM wp_posts
Replace TERM_ID
with the number you found in wp_terms.

fialoppan12
- 21
- 3
1
don't need to use mySql, you can do it with bulk actions in your wp admin
- Create your categories as usual.
- Go to your entries and select them all
- Select in bulk actions / edit
- Edit all at once.

Mauro
- 1,472
- 12
- 22
-
This does not answer the question. I have 181,000 posts, still think I should use the bulk editor? How long will that take to complete. – J. Martin Nov 07 '19 at 07:40
-3
Mauro above suggested bulk editing which is your easiest way to go. I would suggest these steps:
- In the wordpress post editor, click on "Screen Options" and select 100 posts per page.
- Now you can edit 100 posts at a time. So click the checkbox by the "Title" to select all posts on the page.
- From the "bulk actions" dropdown select "edit" and click "Apply"
- Click the category you want the posts added to.
- Click "Update"!
- Do it again for page 2-10, as many as you have. By saving 100 at a time it's just 10 saves to go through 1000 posts and it's safer than touching the DB.

Yavor
- 671
- 3
- 9
-
1You are not answering the question. He's asking by using sql query, not via WordPress. – WendiT Jun 11 '16 at 05:04