Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



register_taxonomy ›

Seit2.3.0
Veraltetn/v
register_taxonomy ( $taxonomy, $object_type, $args = array() )
Parameter: (3)
  • (string) $taxonomy Taxonomy key, must not exceed 32 characters.
    Erforderlich: Ja
  • (array|string) $object_type Object type or array of object types with which the taxonomy should be associated.
    Erforderlich: Ja
  • (array|string) $args { Optional. Array or query string of arguments for registering a taxonomy.
    Erforderlich: Nein
    Standard: array()
Gibt zurück:
  • (WP_Error|void) WP_Error, if errors.
Definiert in:
Codex:
Changelog:
  • 4.2.0
  • 4.4.0
  • 4.4.0
  • 4.5.0
  • 4.7.0
  • 5.0.0

Creates or modifies a taxonomy object.

Note: Do not use before the {@see 'init'} hook.

A simple function for creating or modifying a taxonomy object based on the parameters given. If modifying an existing taxonomy object, note that the $object_type value from the original registration will be overwritten.



Quellcode

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

	if ( ! is_array( $wp_taxonomies ) )
		$wp_taxonomies = array();

	$args = wp_parse_args( $args );

	if ( empty( $taxonomy ) || strlen( $taxonomy ) > 32 ) {
		_doing_it_wrong( __FUNCTION__, __( 'Taxonomy names must be between 1 and 32 characters in length.' ), '4.2.0' );
		return new WP_Error( 'taxonomy_length_invalid', __( 'Taxonomy names must be between 1 and 32 characters in length.' ) );
	}

	$taxonomy_object = new WP_Taxonomy( $taxonomy, $object_type, $args );
	$taxonomy_object->add_rewrite_rules();

	$wp_taxonomies[ $taxonomy ] = $taxonomy_object;

	$taxonomy_object->add_hooks();


	/**
	 * Fires after a taxonomy is registered.
	 *
	 * @since 3.3.0
	 *
	 * @param string       $taxonomy    Taxonomy slug.
	 * @param array|string $object_type Object type or array of object types.
	 * @param array        $args        Array of taxonomy registration arguments.
	 */
	do_action( 'registered_taxonomy', $taxonomy, $object_type, (array) $taxonomy_object );
}