Created
January 3, 2011 17:06
-
-
Save franz-josef-kaiser/763694 to your computer and use it in GitHub Desktop.
Interim fn for Wordpress has_term(), that will come with WP 3.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*************************************************** | |
* DISCONTINUED - PLEASE UPDATE TO WORDPRESS v 3.1 | |
***************************************************/ | |
/** | |
* post_has_term() | |
* must be used inside the loop | |
* not tested with arrays so far | |
* until WP 3.1 | |
* @param $tax auto lowercase for slug | |
* @param $term auto lowercase for slug | |
* @return bool if one term was found | |
*/ | |
if ( !function_exists('has_term') ) { | |
function post_has_term( $tax = '', $term = '' ) { | |
$terms = get_the_terms( $post->ID, $tax, '' ); | |
// Array | |
if ( is_array($term) ) { | |
foreach ($term as $searched) { | |
foreach ($terms as $t) { | |
$bool_arr[] .= ( $t->slug == strtolower($searched) ) ? true : false; | |
} | |
} | |
return in_array('true', $bool_arr) ? true : false; | |
} | |
// no Array | |
else { | |
foreach ($terms as $t) { | |
return $has_term = ( $t->slug == strtolower($term) ) ? true : false; | |
} | |
} | |
} | |
} | |
elseif ( current_user_can('administrator') ) { | |
wp_die( __('Upgrade Notice', 'text_domain'), __('You should go and replace your post_has_term()-function with the now avaible has_term() function from WP-Core.', 'text_domain') ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment