[wp-hackers] Treating categories like tags
mike at newclarity.net
Fri Feb 8 10:16:31 UTC 2013
On Feb 8, 2013, at 3:49 AM, David Anderson <david at wordshell.net> wrote:
> I've got a site where the owner has so many categories, that he prefers to have the "categories" box on the post page appear like the "tags" box - i.e. have it not display the kitchen sink, but instead auto-complete, with an optional cloud.
> A quick experiment shows that this can be changed by editing create_initial_taxonomies in wp-includes/taxonomy.php, and finding the register_taxonomy call, changing the 'hierarchical' parameter from 'true' to 'false', and adding in some new 'labels' parameters (because by default non-hierarchical taxonomies get called 'tags').
> However this leaves me with a couple of questions that I'm not sure on the best way to deal with. Can anyone advise?
> * By making it non-hierarchical, hierarchy pages disappear (e.g. www.example.com/category/parent-cat/child-cat is now a 404). I suppose the owner will want these to automatically redirect, in this example to www.example.com/category/child-cat. What would be the best practice on how to do this? (It may be a moot question, as I haven't checked that the owner has any nested categories. But I and perhaps others would learn something anyway).
> * Are there likely to be any other issues in converting an existing hierarchical taxonomy to a non-hierarchical one? In particular, any issues in converting this particular, built-in-default one? What side-effects might this have; or is there a better way I can solve my problem?
I haven't verified that what I'm going to suggest won't cause other problems but have you tried using an 'admin_init' hook to modify the 'hierarchical' parameter from 'true' to 'false' but only for when $pagenow is either 'post.php' or 'post-new.php'? That way on non-admin page loads they are and the category section on the admin won't have been modified to treat them an non-hierarchical (but I can't promise there won't be side-effects I'm not considering.)
We've found similar approaches have worked well for us in the past.
More information about the wp-hackers