Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

If statement for custom taxonomy WordPress

  • SOLVED

I've create a custom post type called "work" and have added a hierarchical taxonomy called "medium" to it.

I've added the following "mediums" : "television", "print" and "outdoor".

Within the single-work.php file, how do I use these new "mediums" to display content differently for each one?

For instance, with posts I have used:
if (is_category("television") {
// do this;
}else{
// do that;
}


What's the equivalent for custom taxonomies? I know the below doesn't work, but that's what I'm aiming for
if (is_medium("television") {
// do this;
}else{
// do that;
}

Answers (3)

2011-05-09

Michael Fields answers:

The correct function to use inside the loop is: has_term().

[[LINK href="http://codex.wordpress.org/Function_Reference/has_term"]]http://codex.wordpress.org/Function_Reference/has_term[[/LINK]]

if ( has_term( 'televison', 'medium' ) )


Michael Brumm comments:

I tried this and it doesn't seem to be working either.

FYI, I'm using the [[LINK href="http://codecanyon.net/item/easy-custom-content-types-for-wordpress/234182"]]Easy Custom Content Types[[/LINK]] plugin to create the Custom Post Type and Taxonomy. I've included a screensnap of the taxonomy in case I screwed something up there.

<?php
/**
* Single Page Template File
*
*/

get_header(); ?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<ul id="pagenav">
<li><?php previous_post_link_plus( array('loop' => true, 'order_by' => 'menu_order', 'link' => 'Prev')); // outputs the first post ?></li>
<li><a href="<?php echo home_url( '/' ); ?>">Thumbnails</a></li>
<li><?php next_post_link_plus( array('loop' => true, 'order_by' => 'menu_order', 'link' => 'Next')); // outputs the last post ?></li>

</ul>

<div class="clearing"></div>

<div id="holder">

<?php if ( has_term('televison', 'medium')) { ?>
<h2>TV - <?php the_title(); ?></h2>
<?php the_content(); ?>

<?php } else {?>
<img src="<?php echo get_post_meta($post->ID, 'ecpt_largeimage', true); ?>" class="noborder" />
<h2>OTHER WORK - <?php the_title(); ?></h2>
<?php the_content(); ?>
<p><?php echo get_post_meta($post->ID, 'ecpt_keywords', true); ?></p>
<?php } ?>

<?php if( function_exists('ADDTOANY_SHARE_SAVE_KIT') ) {
echo "<p>";
ADDTOANY_SHARE_SAVE_KIT();
echo "</p>";} ?>
<?php endwhile; // end of the loop. ?>
</div>

<?php get_footer(); ?>