Register custom taxonomy

add_action( 'init', 'create_my_taxonomies', 0 );

function create_my_taxonomies() {

register_taxonomy( 'my_new_taxonomy1', 'post', array( 'hierarchical' => false, 'label' => 'My New Taxonomy1', 'query_var' => true, 'rewrite' => true ) );

register_taxonomy( 'my_new_taxonomy2', 'post', array( 'hierarchical' => false, 'label' => 'my_new_taxonomy2', 'query_var' => true, 'rewrite' => true ) );



<!-- For your post to display tag cloud for your new taxonomy -->

<?php wp_tag_cloud( array( 'taxonomy' => 'my_new_taxonomy1', 'number' => 45 ) ); ?>

<!-- /End -->

<!-- Display taxonomy terms for each post -->

<?php echo get_the_term_list( $post->ID, 'my_new_taxonomy1', 'My New Taxonomy1: ', ', ', '' ); ?>

<!-- /End -->

<!-- Show posts from a certain taxonomy -->

<?php query_posts( array( 'people' => 'will-smith', 'showposts' => 10 ) ); ?>


You must be logged in to post a comment.

  1. You may not need the action, but having complete control of when you run functions is key to keeping your head on straight. Also wordpress plugins or theme templates files may be loaded more than once during wordpress' execution, so triggering functions via an action can also keep down on un necessary function calls.

    Thanks - In general if it works, go with it I say. Half this stuff is pure trial and error.

  2. Adam -- easy quesion. I'm about ankle-deep into taxonomies and understand your code (I've come a long way!). What I don't see is the need for the

    add_action( 'init', 'create_my_taxonomies', 0 );
    function create_my_taxonomies() {

    Some tutorials don't use the init and function; others do. What is the purpose and why use these as registering taxonomies w/o them seems to work as well.