最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

database - How to AssignMove all Deleted post to a category

programmeradmin1浏览0评论

I have a database of 50,000 articles, One of my categories contains post of 30k, I mistakenly Deleted a category that contains 30k Post, But all the posts still exist.

I have search google for the past 2days now but I still can't find a way to move this 30k to a new category I just created.

Please help me out, I have access to PHPMyAdmin

INSERT IGNORE INTO wp_term_relationships
(object_id, term_taxonomy_id)
(  
   SELECT DISTINCT ID, 3
   FROM wp_posts
   WHERE post_type = 'post' AND post_status = 'publish'
);

I find the above code helpful but it moves ALL the posts of the entire site to a category, I just need only the post that was deleted

I have a database of 50,000 articles, One of my categories contains post of 30k, I mistakenly Deleted a category that contains 30k Post, But all the posts still exist.

I have search google for the past 2days now but I still can't find a way to move this 30k to a new category I just created.

Please help me out, I have access to PHPMyAdmin

INSERT IGNORE INTO wp_term_relationships
(object_id, term_taxonomy_id)
(  
   SELECT DISTINCT ID, 3
   FROM wp_posts
   WHERE post_type = 'post' AND post_status = 'publish'
);

I find the above code helpful but it moves ALL the posts of the entire site to a category, I just need only the post that was deleted

Share Improve this question edited Jul 22, 2019 at 15:53 XATA asked Jul 22, 2019 at 15:05 XATAXATA 6712 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Option 1: backup - Many hosts offer backups. Sometimes you have to pay for them, but often even when you do, they've actually been backing everything up and paying just allows you to access them. Worth checking as this will be fastest.

Option 2: post listing screen - If these posts all had only 1 category, the one that was deleted, they'll be uncategorized now. You can go to the All Posts screen in wp-admin to find all the uncategorized posts, use Screen Options up at the top to show however many you want at a time - I'd suggest 100 at a time - and page by page, check all and bulk edit to assign the new category.

Option 3: if all else fails - If you have no backup and the posts have other categories, but you have a list of the particular posts you want to put back in the category, you can run queries in phpMyAdmin to associate these posts to that category. You'll want to first find the post ID of every post you're trying to add into the category, and then you can find the query that will associate those post IDs to the category.

You can't just restore a backup? If not, this is the simplest thing I can think of...

Sounds like you want to move all posts with category "Uncategorized" to a new category. You could do this with SQL but a quicker way might be to just change the name and slug of the uncategorized category.

Go into the admin > Posts > Categories and hit the edit button by "Uncategorized". Change the Name and Slug and all those posts will be in the new category.

You can then create a new default category then change the default category in Settings > Writing.

Note: Be sure to backup your database before messing around with any of this.

发布评论

评论列表(0)

  1. 暂无评论