Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active December 18, 2021 14:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilgee/b60b7407c33307ccc539108e2cbc2a5a to your computer and use it in GitHub Desktop.
Save neilgee/b60b7407c33307ccc539108e2cbc2a5a to your computer and use it in GitHub Desktop.
Output a Custom Taxonomy Loop of Terms
<?php
// Taxonomy Loop
/**
* Get the Custom Taxonomy
* For a list of other parameters to pass in see link below
* @link https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
* For a list of get_term return values see link below
* @link https://codex.wordpress.org/Function_Reference/get_term
*
*/
$terms = get_terms( array(
'taxonomy' => 'custom_taxonomy_name', // Swap in your custom taxonomy name
'hide_empty' => true,
));
echo '<ul>';
// Loop through all terms with a foreach loop
foreach( $terms as $term ) {
// Use get_term_link to get terms permalink
// USe $term->name to return term name
echo '<li><a href="'. get_term_link( $term ) .'">'. $term->name .'</a></li>';
}
echo '</ul>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment