I’m working on a massive WordPress migration project and after we defined taxonomies they needed to be changed or updated. I tried doing this with SQL but that turned into an Inner Join nightmare due to how taxonomies are related to posts in the database. This script also comes in handy if you want to run mass updates to add all posts to a new category. When you are dealing with thousands of pages doing this manually in the WordPress admin becomes tedious.
So, you can drop these handy little scripts in your theme’s functions.php file for one time updates. These work for posts, pages, custom post types along with categories, tags, and custom taxonomies.
Apply Category To All Posts
Swap All Pages From One Custom Taxonomy Category To Another
This is one of the main reasons I wrote this script. We had hundreds of miss-classified pages in our custom taxonomy and I wanted to swap everything categorized as “News Releases” to another category called “Featured”. As mentioned above
Hopefully this saves you some time. Let me know in the comments if you have any questions.
If you have already defined your custom taxonomy in another plugin and want to use it in a custom post type that you might register in a second plugin, you’ll need to add something like this in your custom post type definition.
The ‘register_taxonomy_for_object_type($taxonomy, $object_type)‘ function is quite nifty. I’ve also used it to enable the standard Category taxonomy on Pages.
This is for those of you hunting for the Cheatin’ uh? WordPress error when developing custom post types.
It’s most likely an issue with what you named a custom taxonomy that you intend to attach to a custom post type.
In our case we had…
[code]register_taxonomy("Types", array("portfolio"), array("hierarchical" => true, "label" =>; "Types", "singular_label" => "Type", "rewrite" =&> true));[/code]
This is a frustrating error because you simply get the “Cheatin uh?” message.
Here’s the fix
[code]register_taxonomy("types", array("portfolio"), array("hierarchical" => true, "label" => "Types", "singular_label" => "Type", "rewrite" => true));[/code]
Notice the difference? The fix is your custom taxonomy’s name has to be lower case. That should save you a couple hour hunt down a rabbit hole.