Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: None  |  size: 0.65 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Conditional Tags for Custom Taxonomy in Custom Post Type
  2. <?php if (has_custax('a-custax')) {
  3.     echo 'do something A';
  4. } else {
  5.     echo 'do something B';
  6. }
  7.        
  8. <?php function has_custax( $custax, $_post = null ) {
  9.     if ( empty( $custax ) )
  10.         return false;
  11.     if ( $_post )
  12.         $_post = get_post( $_post );
  13.     else
  14.         $_post =& $GLOBALS['post'];
  15.     if ( !$_post )
  16.         return false;
  17.     $r = is_object_in_term( $_post->ID, 'custax', $custax );
  18.     if ( is_wp_error( $r ) )
  19.         return false;
  20.     return $r;
  21. }
  22. ?>
  23.        
  24. <?php if ( has_custax( 'a-custax', $post->ID ) ) {
  25.       echo 'do something A';
  26. } else { echo 'do something B'; }; ?>