1

I recently had a web site redesigned and migrated to another domain. The new site uses Wordpress as a CMS for the whole site (it just managed the blog on the previous one). Somehow in the process of setting up the new site, the designer added a whole slew of categories, 953 of them to be exact, and most of them have zero posts attached and will never be used.

I want to clear these zero-categories out, but it would take forever using the WP interface to do this, which only shows 20 at a time. Is there some way to do it with a MySQL operation? I'm reluctant to just delete them from the categories table because I don't know how they are linked elsewhere in the DB. OTOH maybe if the category has zero posts it doesn't matter?

I know there is some WP method to safely do this because the categories page on the dashboard has to call it when you delete a category, but I can't figure out what it is from looking at the form.

4

2 に答える 2

3

私のために働いたのは:

DELETE FROM `wp_term_taxonomy` WHERE taxonomy = 'category' AND term_taxonomy_id NOT IN (SELECT term_taxonomy_id FROM `wp_term_relationships`);

DELETE FROM `wp_terms` WHERE term_id NOT IN (SELECT term_id FROM `wp_term_taxonomy`);

注意1:以前にデータベースをバックアップすることをお勧めします。

注意2:これにより、空でない子カテゴリの空の親カテゴリも削除されます。このような場合は、後でテーブルのparent列を更新する必要があります。wp_term_taxonomy

于 2018-04-09T23:56:00.080 に答える
2

コントロールパネルの上部にある[画面オプション]ボタンをクリックすると、WPインターフェイスに表示するカテゴリの数を選択し、チェックボックスを使用して一括削除を実行できます。

于 2012-08-29T16:14:08.173 に答える