0

I have several custom post types : Testimony, questions and FAQ. They all have a taxonomy called "category". In the record function of the custom post type they all have this line:

'taxonomies' => array( 'category' ),

The problem is :If I start creating "categories" for one of the custom post types, it also creates them for the other custom post types, as if there was only one taxonomy called "category", common to the set of custom post types

The SQL query which consists in renaming a taxonomy works if it targets only one taxonomy.

UPDATE  `wp_term_taxonomy` SET  `taxonomy` =  '<new taxonomy name>' WHERE  `taxonomy` = '<old taxonomy name>';

Same with the "rename taxonomy" plugin.

Is there a way to rename custom post type taxonomy by making them independent of each other? I tried to modify the name of a taxonomy directly in the registration function, but obviously it deleted all the categories I had created

5
  • 1
    so you have posts from multiple post types in the same category? Then there is only 1 single category, WP doesn't create a term for each CPT, so asking how to rename them separately doesn't make sense, for that to make sense there would need to be separate terms with the same name, unless I've misunderstood? Your question was very difficult to follow though, perhaps if you used named examples of categories and post types it would be easier to understand?
    – Tom J Nowell
    May 23, 2023 at 15:24
  • Thanks Tom, I edited the question. In fact no, I have several custom post type, and they all have the same taxonomy name. When creating a custom post type, we can create a taxonomy. Here I have 3 custom post type, they all have a taxonomy called "category", which is problematic.
    – blogob
    May 23, 2023 at 19:55
  • when you say they all have a taxonomy named category do you mean that there are multiple custom taxonomies, one for each CPT that have the same name, or, do you mean that the original developers reused the categories that come with WordPress and allowed them to be used with these new CPTs? If you can share the code to be more specific about this then that will save a lot of confusion, right now there are still ambiguities as what you said could mean multiple things. CPT registration code and Custom taxonomy registration code will be helpful if you can edit that into your question
    – Tom J Nowell
    May 24, 2023 at 11:44
  • hello Tom, thanks, I edited my question. I'm talking about custom post type and taxonomy only, not regular category. So yest, they all have a taxonomy named category or here are multiple custom taxonomies, one for each CPT that have the same name
    – blogob
    May 26, 2023 at 4:38
  • I understood that but there are multiple ways to interpret "they all have a taxonomy named category", I was hoping seeing the code would make it clear which one you're talking about as they're all fundamentally different and have conflicting answers. E.g. for 5 CPTs is there 1 Custom taxonomy? Or 5 custom taxonomies? It's not clear and never explicitly stated in your question, only implied. Sharing the code would have cleared this up quickly
    – Tom J Nowell
    May 26, 2023 at 9:47

1 Answer 1

0

There is no magic plugin or SQL query that will do this for you.


Why It's Broken and Not in The Way You Thought

There is only one taxonomy, because of this:

'taxonomies' => array( 'category' ),

While your sites code may have registered multiple custom taxonomies perhaps even with different names, URLs, and semantics, because they all use the name category the database does not distinguish between them, and they are the same taxonomy.

Editing A in the first one doesn't also edit A in the second one, they are literally the same term and there is no distinction, there is only 1 entry in the database, not 2.

Because there is only 1 term, not 2, there is nothing to rename to fix this.

Note that sometimes using a single taxonomy across multiple post types is desirable and useful.

Fixing This

This will be painful and time consuming to fix, as it has to be done almost entirely by hand.

You need to create new taxonomies with unique names that do not match, adjust all your post type registrations to use those instead, then create new terms and assign them to your posts. Taxonomies is the easiest part as you would need to prefix the taxonomy slug/name to fix the problem for future terms, and use the new name in the CPT registration. Migrating content is the difficult part

This will be very heavy on manual work, and there is little that can be done to avoid it. The best you can hope for is being able to duplicate the terms in another taxonomy to save time on recreating them, but the bulk of the work is in re-assigning posts, and if you do it on a per post basis the term recreation is done as you're entering terms.

2
  • Thank you very much Tom. When I realized that each custom post type had the same taxonomy called "category" I immediately thought that it would be problematic to create loops or other functions related to my custom posts. So I recreated a cutsom fields select with the names of my different categories in acf to simulate these categories and be able to loop over them,. But from what you say, in fact there is no problem to have the same taxonomy for all custom post type.. so i will have to review everything.. thanks for the help
    – blogob
    May 26, 2023 at 13:22
  • registering multiple taxonomies with the same name may lead to weirdness, if you intend for them all to share one taxonomy you can do that but only register the taxonomy once
    – Tom J Nowell
    May 26, 2023 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.