问题
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 !
回答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.
回答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.
回答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.
来源:https://stackoverflow.com/questions/26262878/how-to-add-category-to-all-post-by-using-sql-query