Using Your Custom Taxonomy in WordPress

If you have been created your custom taxonomy, if not than please read this article http://www.webdirectors.co.uk/creating-custom-taxonomies-wordpress-web-designer-london/ because in this article you know that how to use custom taxonomy in your website. The some features of Wordperss are very easy-to-use functions for working with your custom taxonomy. Below the following shows how you can display a tag cloud showing your custom taxonomy terms:

<?php wp_tag_cloud( array( ‘taxonomy’ => ‘type’, ‘number’ => 7 ) ); ?>

Above the wp_tag_cloud() function use, it can accept many different arguments, you’re using only two parameters in this example: these are taxonomy and the number. The first parameter set the taxonomy to type; it tells that the WordPress to return only taxonomy terms it defined under the custom taxonomy you created for types. In the next parameter define the number of terms that you want to display, in this example are 7. After calling this function in your theme sidebar it displays a nice tag cloud that shows the seven taxonomy terms with the most products assigned to them.

The custom Loop using WP_Query you can also use to display products for a specific taxonomy term. If you want to display only products that are in the web design type by create a custom Loop:

<?php
$args=array(‘post_type’=>’products’,’tax_query’=>array(array(‘taxonomy’=>’type’,’field’=>’slug’,’terms’=>’web design’)));
$products = new WP_Query( $args );
while ( $products->have_posts() ) : $products->the_post();
echo ‘<p>’ .get_the_title(). ‘</p>’;
endwhile;
wp_reset_postdata();
?>

There are two arguments send in the WP_Query, first the post_type, products in the above example, and second tax_query, which specifies which taxonomy term to use these arguments send by the variable $args.

Here you can also easily display the custom taxonomy terms assigned to each post. For do this task here you’ll be using the get_the_term_list() WordPress function. The get_the_term_list() function works very similarly to get_the_tag_list() but is for building a custom taxonomy term list instead.

<?php echo get_the_term_list($post->ID,’type’,’Product Type: ‘,’,’,” );?>

Above code will displays all the custom taxonomy terms that assigned to the post you are seeing. The above cod does need to be in the Loop in your theme template file to work properly. Here you send in the post ID, name of the custom taxonomy, and the title that you want displayed next to the terms to execute the function. For every wordpress function you can always visit this http://codex.wordpress.org/Function_Reference/get_the_term_list/link find here you know also in detail that what parameters are allowed in this function and other:

To retrieve or fetch an array of your custom taxonomy values the get_terms() function can also be used.
Below example, retrieve all of the terms for your type taxonomy and the values displaying the term name through the loop:

<?php
$terms = get_terms( ‘type’ );
foreach ( $terms as $term ) {
echo ‘<p>’ .$term->name. ‘</p>’;
}
?>

Remember that before you start working with custom taxonomy values you need to make sure the taxonomy is defined. Any result of the preceding examples return blank, then it means that they were executed before your register_taxonomy() function was called to define your custom taxonomy.

To organize your website content is a very powerful way to Defining custom taxonomies in WordPress. So using the above examples and methods it can help transform your website into a content management system using the power of WordPress.