Advertisements

register_taxonomy

Definition:
function register_taxonomy( $taxonomy, $object_type, $args = array() {}

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.

Parameters

  • string $taxonomy: Name of taxonomy object
  • array|string $object_type: Name of the object type for the taxonomy object.
  • array|string $args: See above description for the two keys values.

Source code

function register_taxonomy( $taxonomy, $object_type, $args = array() ) {

	global $wp_taxonomies, $wp_rewrite, $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'] && '' != get_option('permalink_structure') ) {

		$args['rewrite'] = wp_parse_args($args['rewrite'], array(

			'slug' => sanitize_title_with_dashes($taxonomy),

			'with_front' => true,

			'hierarchical' => false

		));



		if ( $args['hierarchical'] && $args['rewrite']['hierarchical'] )

			$tag = '(.+?)';

		else

			$tag = '([^/]+)';



		$wp_rewrite->add_rewrite_tag("%$taxonomy%", $tag, $args['query_var'] ? "{$args['query_var']}=" : "taxonomy=$taxonomy&term=");

		$wp_rewrite->add_permastruct($taxonomy, "{$args['rewrite']['slug']}/%$taxonomy%", $args['rewrite']['with_front']);

2685

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: