Codex tools: Log in / create account
Contents |
This function adds or overwrites a taxonomy. It takes in a name, an object name that it affects, and an array of parameters. It does not return anything.
<?php register_taxonomy($taxonomy, $object_type, $args); ?>
<?php register_taxonomy('foo', 'post', array('hierarchical' => true)); ?>
Wordpress 2.8 will automatically build an admin interface for custom taxonomies. Allowing end users to add terms and associate posts with the taxonomy terms.
You can define custom taxonomy terms in a template's function.php file:
<?php
//hook into the init action and call create_pc_db_taxonomies when it fires
add_action( 'init', 'create_pc_db_taxonomies', 0 );
//create two taxonomies, actor and director
function create_pc_db_taxonomies() {
register_taxonomy( 'actor', 'post', array( 'hierarchical' => false, 'label' => __('Actors', 'series'), 'query_var' => 'actor', 'rewrite' => array( 'slug' => 'actors' ) ) );
register_taxonomy( 'director', 'post', array( 'hierarchical' => false, 'label' => __('Directors', 'series'), 'query_var' => 'director', 'rewrite' => array( 'slug' => 'directors' ) ) );
}
?>
Since: 2.3.0
register_taxonomy() is located in wp-includes/taxonomy.php.