With this simple function, designed for wordpress, you can retrieve the post tag name by the post tag ID or slug. Just provide the the ID or slug as the function parameter and the function will return the tag name.
<?php
/**
* GetTagName()
* Retrieves the post tag name by the ID or slug
* @param mixed $meta
* @return string The TagName
*/
function GetTagName($meta){
if (is_string($meta) || (is_numeric($meta) && !is_double($meta))
|| is_int($meta)){
if (is_numeric($meta))
$meta = (int)$meta;
if (is_int($meta))
$TagSlug = get_term_by('id', $meta, 'post_tag');
else
$TagSlug = get_term_by('slug', $meta, 'post_tag');
return $TagSlug->name;
}
}
// Get by slug
echo GetTagName(get_query_var('tag'));
// Get by ID
echo GetTagName('441');
// Get by slug
echo GetTagName('tag-slug');
?>
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)


» Latest comments