Is there a way to add a parameter to an already-registered custom taxonomy? All of my taxonomies were built with a plugin, so it would be nice if I could add something to functions.php that would just add 'rewrite' => array( 'hierarchical' => true ) to those taxonomies.
You should be able to use register_taxonomy
to re-register the taxonomy you want to affect.
http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/taxonomy.php#L305
WARNING: Untested code!
(Just off the top of my head, mostly. I take no responsibility for broken sites.):
function reregister_taxonomy() {
# the post types that the taxonomy is registered to
$post_types = array('post');
# set this to the taxonomy name
$tax_name = 'TAXONOMY_NAME_TO_CHANGE';
# load the already created taxonomy as array so we can
# pass it back in as $args to register_taxonomy
$tax = (array)get_taxonomy($tax_name);
if ($tax) {
# adjust the hierarchical necessities
$tax['hierarchical'] = true;
$tax['rewrite']['hierarchical'] = true;
# adjust the hierarchical niceties (these could be ignored)
$tax['labels']['parent_item'] = sprintf(__("Parent %s"),
$tax->labels->singular_name);
$tax['labels']['parent_item_colon'] = sprintf(__("Parent %s:"),
$tax->labels->singular_name);
# cast caps to array as expected by register_taxonomy
$tax['capabilities'] = (array)$tax['cap'];
# cast labels to array
$tax['labels'] = (array)$tax['labels'];
# register the taxonomy with our new settings
register_taxonomy($tax_name, array('post'), $tax);
}
}
# init action with a late priority so other taxonomies are loaded
# alternatively could be done with the `registered_taxonomy` action hook
add_action('init', 'reregister_taxonomy', 9999);
Only after writing this did I realize this question was a year-and-a-half old, mayhaps somebody will find it useful anyhow.