Question

I want to keep this category title on my pages, but I don't want it to be a link.

<?php echo get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' '); ?>

Can anyone help? Thanks

Was it helpful?

Solution

You could use get_the_terms() and wp_sprintf_l():

function wpse_52878_term_list( $args = array() )
{
    $default = array (
        'id'               => get_the_ID(),
        'taxonomy'         => 'post_tag',
        'before'           => '',
        'after'            => '',
    );

    $options = array_merge( $default, $args );
    $terms   = get_the_terms( $options['id'], $options['taxonomy'] );
    $list    = array();

    foreach ( $terms as $term )
    {
        $list[] = $term->name;
    }
    return $options['before'] . wp_sprintf_l( '%l', $list ) . $options['after'];
}

echo wpse_52878_term_list( array ( 'id' => get_the_ID(), 'taxonomy' => 'portfolio_cats' ) );

Another option:

echo wp_strip_all_tags( 
    get_the_term_list( get_the_ID(), 'portfolio_cats', ' ', ' , ', ' ') 
);

OTHER TIPS

Why not use this?

<?php
$portfolio_cats = wp_get_object_terms(get_the_ID(), 'portfolio_cats', array('fields' => 'names'));
if(!empty($portfolio_cats)){
    if(!is_wp_error( $portfolio_cats )){
        echo '<ul>';
        foreach($portfolio_cats as $term){
            echo '<li>'.$term->name'</li>'; 
        }
        echo '</ul>';
    }
}

Try a print_r with the returned array to see the contents.

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