Question

Trying to print my custom post type's taxonomy but without the link. Tried this, but doesn't seem to work, any suggestions?

$text = the_terms($post->ID,'type','','',''); 
echo strip_tags($text);

Any help would be greatly appreciated... I'm about to start punching babies.

Was it helpful?

Solution

You could use a filter and strip_tags(), as you suggested. Example using post tags, since that's the taxonomy I had available:

function my_remove_links( $term_links ) { 
    return array_map('strip_tags', $term_links);
}
add_filter('term_links-post_tag', 'my_remove_links');

Really though, I would just get_the_terms() and and craft the output yourself:

function the_simple_terms() {
    global $post;
    $terms = get_the_terms($post->ID,'post_tag','',', ','');
    $terms = array_map('_simple_cb', $terms);
    return implode(', ', $terms);
}   

function _simple_cb($t) {
    return $t->name;
}

echo the_simple_terms();

OTHER TIPS

the_terms() echos the output and returns null. So your first line is echoing the terms with the anchor tags and then your echoing null in the second line. You want to use get_the_terms().

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top