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.
Can try this:
Just use strip_tags
If you just want the terms assigned to a specific post:
If you want ALL of the terms:
I ran into a similar problem yesterday, and came up with the follow solution:
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.
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:
If you want the terms ordered by slug rather than name then use this…