Codex

Function Reference/register taxonomy

Contents

Description

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.

Usage

 <?php register_taxonomy($taxonomy$object_type$args); ?> 

Parameters

$taxonomy
(string) (required) The name of the taxonomy.
Default: None
$object_type
(array/string) (required) A name or array of names of the object type(s) for the taxonomy object.
Default: None
$args
(array/string) (optional) An array of arguements.
Default: None

Arguments

hierarachical 
(boolean) Has some defined purpose at other parts of the API.
update_count_callback 
(string) A function name that will be called when the count is updated.
rewrite 
(array|false) False to prevent rewrite, or array('slug'=>$slug) to customize permastruct; default will use $taxonomy as slug.
query_var 
(string|false) False to prevent queries, or string to customize query var (?$query_var=$term); default will use $taxonomy as query var.

Example

<?php register_taxonomy('foo''post', array('hierarchical' => true)); ?> 

Notes

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' ) ) ); } ?>

Change Log

Since: 2.3.0

Source File

register_taxonomy() is located in wp-includes/taxonomy.php.

Related

See also index of Function Reference and index of Template Tags.