I’m currently using <?php echo get_the_term_list( $post->ID, 'tag', '', '', '' ); ?> to return the list of tags attached to a custom post type in index.php and single.php.
Some of the posts have upwards of 20 tags attached, I need to keep these but only display the top 5 on the page.
I’ve looked at a few options including wp_get_object_terms and get_objects_in_term but can’t seem to get the right combination of arguments.
Any ideas?
Looking at the source code for get_the_term_list, there’s a filter you can attach to which processes the terms before they’re output, so if you put the following in your functions.php:
assuming, of course, that your taxonomy is called ‘tag’ – if not, change the filter name accordingly.