I’m looking to create custom links for my WordPress terms, I’ve done the following:
<?php $terms = get_the_terms( $post->ID, 'blog' );
if ( $terms && ! is_wp_error( $terms ) ) :
$blog_links = array();
$blog_slugs = array();
foreach ( $terms as $term ) {
$blog_links[] = $term->name;
}
foreach ( $terms as $termslug ) {
$blog_slugs[] = $termslug->slug;
}
$blog = join( ", ", $blog_links );
$blogs = join( ", ", $blog_slugs );
?>
<a href="<?php bloginfo('url'); ?>/blog/<?php echo $blogs; ?>"><?php echo $blog; ?></a>
<?php endif; ?>
This creates the url:
http://www.domain.com/blog/news,%20guest-blogs
With the text for the link looking like this (I.e it’s making it all one link – see screenshot):

Which is close! I actually want to split each term up into a link (with a comma in between) and make the urls http://www.domain.com/blog/news and http://www.domain.com/blog/guest-blogs. I think I’m missing a foreach to output the each link separately.
Can someone help me get the final bit correct?
might be easy to just use
<?php echo get_the_term_list( $post->ID, 'blog', '', ', ', '' ); ?>something is wrong with your code… maybe something like this will do…