I have two custom taxonomies: 'cities', & 'policy'. I'd like to display all the terms from each taxonomy at the bottom of a post, with links. This is what I would use for a single taxonomy - let's say cities:
echo get_the_term_list( $post->ID, 'cities', '', ' / ', '' );
But I want the list to include terms in cities and terms in policy.
term_links-<taxonomy>
andthe_terms
filter hooks, but how about just call the function once for each the taxonomies.. soecho get_the_term_list( $post->ID, 'policy', '', ' / ', '' );
for thepolicy
taxonomy.<?php echo get_the_term_list( $post->ID, 'cities', '', ' / ', '' ); ?> / <?php echo get_the_term_list( $post->ID, 'policy', '', ' / ', '' ); ?>
$lists = [ get_the_term_list( ... ), get_the_term_list( ... ) ];
, then join them using your divider:echo implode( ' / ', array_filter( $lists ) );
. Alternatively, you can usewp_get_post_terms()
to get the terms in your taxonomies, then manually loop through the array items and echo a link for each term. Just remember that,wp_get_post_terms()
does not cache the results, soget_the_terms()
is preferred when looping over a posts query result.