How to add category to all post by using sql query?

房东的猫 提交于 2019-12-24 00:44:49

问题


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

  1. Create your categories as usual.
  2. Go to your entries and select them all
  3. Select in bulk actions / edit
  4. 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:

  1. In the wordpress post editor, click on "Screen Options" and select 100 posts per page.
  2. Now you can edit 100 posts at a time. So click the checkbox by the "Title" to select all posts on the page.
  3. From the "bulk actions" dropdown select "edit" and click "Apply"
  4. Click the category you want the posts added to.
  5. Click "Update"!
  6. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!