0

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.

2

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();
  • you are incredible that you so much, I ended up using the second option. beautiful. – pete_schuster Oct 28 '10 at 21:24
1

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().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.