Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've searched far and wide to try and find an answer to my question. I'm hoping I can get help here. Here goes...

I'm currently retrieving the terms of my custom taxonomy using:

<?php echo get_the_term_list( $post->ID, 'skills', '<ul><li>', '</li><li>', '</li></ul>' ); ?>

What I'm trying to do is retrieve these same post-specific custom taxonomy terms in a list without them being output as links. I've tried all of the following "solutions," but none of them work. Any help would be appreciated.

Returns the post-specific terms in one long string that can't be put in a list:

$terms_as_text = get_the_term_list( $post->ID, 'skills', '<ul><li>', '</li><li>', '</li></ul>' ) ;
echo strip_tags($terms_as_text);

Returns a list of all the terms used across all the custom post types:

<ul>
<?php $args = array( 'taxonomy' => 'skills', 'orderby' => 'ID', 'order' => 'ASC' );
$categories = get_categories( $args );
foreach($categories as $category) { echo '<li> '. $category->name . '</li>'; } 
                ?>
</ul>

Returns nothing:

<?php $args = array('orderby' => 'name', 'order' => 'ASC', 'fields' => 'all');
wp_get_object_terms( $post->ID, $skills, $args );
?>

I've even tried get_the_terms, get_terms, and get_categories to no avail.

share|improve this question
    
Here is solution to get an array of custom taxonomies using wp_list_categories and walker -> Generate array of custom taxonomies using wp_list_categories in WordPress –  Tirumal Rao Mar 15 '13 at 6:49

6 Answers 6

up vote 3 down vote accepted

Can try this:

$terms = get_the_terms ($post->id, 'skills');
if ( !is_wp_error($terms)) : ?>

<?php 
    $skills_links = wp_list_pluck($terms, 'name'); 

    $skills_yo = join(", ", $skills_links);
    ?>

    <span><?php echo $skills_yo; ?></span>
share|improve this answer
    
I updated the example on the get_the_terms page. Not sure what that unset is suppose to do for starters... –  t31os Jul 21 '11 at 9:59
    
Ya neither did I but was a lazy copy/paste –  Wyck Jul 21 '11 at 14:54
    
Thanks both @t31os and Wyck for the help. Here's the code I ended up using which was based on here and the codex. '<?php $terms = get_the_terms( $post->id, 'skills' ); if ( !is_wp_error($terms)) : $skills_links = array(); foreach ($terms as $term) { $skills_links[] = $term->name; $skills = join( "</li><li>", $skills_links ); ?> <ul><li><?php echo $skills; ?></li></ul> <?php endif ?>' –  Certified K Jul 22 '11 at 16:53
    
Sorry about the bad post. I can't figure out how to format so it so it's more readable. –  Certified K Jul 22 '11 at 16:55
function term_clean($postid, $term)
{
    $terms = get_the_terms($postid, $term); 
    foreach ($terms as $term) {  echo $term->name;   };

}
share|improve this answer
$terms = wp_get_post_terms($post->ID, 'TAXONOMYNAME');
$count = count($terms);
if ( $count > 0 ) {
    foreach ( $terms as $term ) {
        echo $term->name . ", ";
    }
}
share|improve this answer

If you just want the terms assigned to a specific post:

<?php $object_terms = wp_get_object_terms( $post_id, 'skills', array( 'fields' => 'names' ) );
if ( $object_terms ) { ?><ul><li><?php echo implode( '</li><li>', $object_terms ); ?></li></ul><?php } ?>

If you want ALL of the terms:

<?php $all_terms = get_terms( 'skills', array( 'fields' => 'names' ) );
if ( $all_terms ) { ?><ul><li><?php echo implode( '</li><li>', $all_terms ); ?></li></ul><?php } ?>
share|improve this answer

I ran into a similar problem yesterday, and came up with the follow solution:

function taxonomy_list( $taxonomy ) {
    $args = array('order'=>'ASC','hide_empty'=>false);
    $terms = get_terms( $taxonomy, $args );
    if ( $terms ) {
        printf( '<ul name="%s">', esc_attr( $taxonomy ) );
        foreach ( $terms as $term ) {
            printf( '<li>%s</li>', esc_html( $term->name ) );
        }
        print( '</ul>' );
    }
}

Then, just paste <?php taxonomy_list( 'TAXONOMY ID' ); ?> in your template file, replacing TAXONOMY ID with whatever the name of the taxonomy is.

My original usage was to create a list of the job categories I have on my job board. Each one then linked to the taxonomy's archive. You can see the full function in my answer on my own Stackoverflow question.

share|improve this answer
// to display taxonomy terms without links: separated with commas
// copy this code in your function.php

function get_taxonony_toDisplay($post_id, $taxonomy_name) {
$terms = wp_get_post_terms($post_id, $taxonomy_name);
$count = count($terms);
if ( $count > 0 ) {
    foreach ( $terms as $term ) {
        echo $term->name . ", ";
    }
}
}

Since I had to display 3 taxonomies separated with commas, so I made a function using Henry's code.

To display use the following line:

<?php get_taxonony_toDisplay($post->ID, 'your_taxonomy_name' ); ?> 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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