register_taxonomy [ WordPress Function ]
| Parameters: |
|
| Uses: |
|
| Defined at: |
|
Create or modify a taxonomy object. Do not use before init.
A simple function for creating or modifying a taxonomy object based on the parameters given. The function will accept an array (third optional parameter), along with strings for the taxonomy name and another string for the object type.
Nothing is returned, so expect error maybe or use taxonomy_exists() to check whether taxonomy exists.
Optional $args contents:
label - Name of the taxonomy shown in the menu. Usually plural. If not set, labels['name'] will be used.
hierarchical - has some defined purpose at other parts of the API and is a boolean value.
update_count_callback - works much like a hook, in that it will be called when the count is updated. Defaults to _update_post_term_count() for taxonomies attached to post types, which then confirms that the objects are published before counting them. Defaults to _update_generic_term_count() for taxonomies attached to other object types, such as links.
rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize permastruct; default will use $taxonomy as slug.
query_var - false to prevent queries, or string to customize query var (?$query_var=$term); default will use $taxonomy as query var.
public - If the taxonomy should be publicly queryable; //@TODO not implemented. defaults to true.
show_ui - If the WordPress UI admin tags UI should apply to this taxonomy; defaults to public.
show_in_nav_menus - true makes this taxonomy available for selection in navigation menus. Defaults to public.
show_tagcloud - false to prevent the taxonomy being listed in the Tag Cloud Widget; defaults to show_ui which defaults to public.
labels - An array of labels for this taxonomy. You can see accepted values in {@link get_taxonomy_labels()}. By default tag labels are used for non-hierarchical types and category labels for hierarchical ones.
Source
<?php
function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
global $wp_taxonomies, $wp;
if ( ! is_array($wp_taxonomies) )
$wp_taxonomies = array();
$defaults = array( 'hierarchical' => false,
'update_count_callback' => '',
'rewrite' => true,
'query_var' => $taxonomy,
'public' => true,
'show_ui' => null,
'show_tagcloud' => null,
'_builtin' => false,
'labels' => array(),
'capabilities' => array(),
'show_in_nav_menus' => null,
);
$args = wp_parse_args($args, $defaults);
if ( false !== $args['query_var'] && !empty($wp) ) {
if ( true === $args['query_var'] )
$args['query_var'] = $taxonomy;
$args['query_var'] = sanitize_title_with_dashes($args['query_var']);
$wp->add_query_var($args['query_var']);
}
if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option('permalink_structure') ) ) {
$args['rewrite'] = wp_parse_args($args['rewrite'], array(
'slug' => sanitize_title_with_dashes($taxonomy),
'with_front' => true,
'hierarchical' => false,
'ep_mask' => EP_NONE,
));
if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] )
$tag = '(.+?)';
else
$tag = '([^/]+)';
add_rewrite_tag( "%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=" );
add_permastruct( $taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite'] );
}
if ( is_null($args['show_ui']) )
$args['show_ui'] = $args['public'];
// Whether to show this type in nav-menus.php. Defaults to the setting for public.
if ( null === $args['show_in_nav_menus'] )
$args['show_in_nav_menus'] = $args['public'];
if ( is_null($args['show_tagcloud']) )
$args['show_tagcloud'] = $args['show_ui'];
$default_caps = array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts',
);
$args['cap'] = (object) array_merge( $default_caps, $args['capabilities'] );
unset( $args['capabilities'] );
$args['name'] = $taxonomy;
$args['object_type'] = array_unique( (array)$object_type );
$args['labels'] = get_taxonomy_labels( (object) $args );
$args['label'] = $args['labels']->name;
$wp_taxonomies[$taxonomy] = (object) $args;
// register callback handling for metabox
add_filter('wp_ajax_add-' . $taxonomy, '_wp_ajax_add_hierarchical_term');
do_action( 'registered_taxonomy', $taxonomy, $object_type, $args );
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/register taxonomy « WordPress Codex
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 ...
codex.wordpress.org - What are these undocumented arguments for register_taxonomy?
May 10, 2012 ... The Wordpress codex has an example of the register_taxonomy() function at http: //codex.wordpress.org/Taxonomies that shows arguments that ...
wordpress.stackexchange.com - register_taxonomy - Create Modify WordPress Taxonomy
Feb 12, 2011 ... Custom taxonomies can be created using register_taxonomy on WordPress site. Taxonomies are a way to group things together. Using small ...
w4dev.com - A refresher on custom taxonomies
Jun 10, 2010 ... The arguments array (third parameter) of register_taxonomy() is the parameter that gives you fine-grain control over how your taxonomy ...
justintadlock.com
Gebruikersdiscussies [ wordpress.org ]
- CharlyLeetham on "Single Taxonomy, Multi Post Types, Can't edit custom post entry"
- Marventus on "Permalinks + Custom Taxonomy"
- mjoanisse on "Permalinks + Custom Taxonomy"
- Marventus on "Permalinks + Custom Taxonomy"
- mjoanisse on "Permalinks + Custom Taxonomy"
- nadine00 on "show taxonomies in a template"
- willshouse on "Add Custom Taxonomy To Author?"
- badfun on "Remove metabox for custom taxonomy"
- Funkatronic on "Remove metabox for custom taxonomy"
- badfun on "Remove metabox for custom taxonomy"