get_term_meta: Source code

By the Web Warlock, Sunday, 23/May/2010 0:41

<?php function get_term_meta( $term_id , $key , $single = false , $use_cache = true , $single_id = 0 ){
	global $wpdb ;
	$table = $wpdb->prefix . "termmeta" ;
	if( $use_cache ){
		$results = get_term_meta_from_cache( $term_id, $key ) ;
	} else {
		$query = $wpdb->prepare( "SELECT meta_value FROM $table WHERE term_id=%d AND meta_key=%s",
			$term_id, (string)$key ) ;
		$results = $wpdb->get_col( $query ) ;
	};
	if ( $single ) {
		list( $max_id , $min_id ) = array( max( 0 , count( $results ) - 1 ) , 0 );
		if( ( 'rand' == mb_strtolower( $single_id ) ) ){
			$single_id = wp_rand( $min_id , $max_id );
		} else {
			$single_id = min( $single_id , $max_id );
		};
		$results = isset( $results[$single_id] ) ? maybe_unserialize( $results[$single_id] ) : NULL ;
	} else {
		$results = array_map( 'maybe_unserialize' , $results );
	};
	$results = apply_filters( 'get_term_meta' , $results ,  $term_id , $key , $single , $use_cache , $single_id ) ;
	return $results ;
}; ?>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment