posts - Why do I have categories with duplicate slugs?

admin2025-06-02  2

I have inherited a WordPress site, where I'm trying to resolve a weird-looking issue related to post categories.

In the Edit Post page, there is nothing showing up under Categories (Gutenberg editor).

Thinking this is strange, I went to the Categories page. There, I saw many categories with the same slug.

This is even more strange to me, since I thought categories couldn't have the same slug. I figure this is where the issue lies.

So I'd like to start deleting these duplicate categories, but there is no Delete link – only View.

Can anyone shed some light on what might be happening here? Can I fix this directly in the database somehow?

I have inherited a WordPress site, where I'm trying to resolve a weird-looking issue related to post categories.

In the Edit Post page, there is nothing showing up under Categories (Gutenberg editor).

Thinking this is strange, I went to the Categories page. There, I saw many categories with the same slug.

This is even more strange to me, since I thought categories couldn't have the same slug. I figure this is where the issue lies.

So I'd like to start deleting these duplicate categories, but there is no Delete link – only View.

Can anyone shed some light on what might be happening here? Can I fix this directly in the database somehow?

Share Improve this question edited Feb 21, 2019 at 1:00 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Feb 20, 2019 at 23:15 Sam NabiSam Nabi 12 bronze badges 1
  • That's super-strange. I think you're going to have to take a look at the database to figure this one out. My best guess is there are some IDs in the term tables that are misaligned or missing. – MikeNGarrett Commented Feb 20, 2019 at 23:19
Add a comment  | 

2 Answers 2

Reset to default 0

Just to note: There will not be a delete option on a category on the Category page if posts are assigned to that category. (Added see below.)

If you want to delete a category, you have to first change those posts to another category. You can do this on the Posts page, sort by category, then a Quick Edit to change the category.

Once there are categories without posts, then you can delete that category.

Changing the values in the table may cause other problems. Probably not severe, but I would guess that you have many posts without categories because you deleted those items in the table.

Added

Apparently the current version of WP allows you to delete categories that have posts assigned.

I recall that not being the case in prior version - 4.9-ish - but cannot tell the exact version. It was within the last year, though.

Answer modified with this new information.

I found a few rows in the wp_terms table with a term_id of 0.

There was also some entries in wp_term_taxonomy with term_taxonomy_id and term_id both set to 0.

After deleting all of those rows, behaviour returned to normal.

Also, I had to fix some issues with the database structure. In the wp_terms table, I had to make sure that AUTO_INCREMENT was enabled for the primary key field.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748871202a314412.html

最新回复(0)