Last active
December 18, 2021 14:01
-
-
Save neilgee/b60b7407c33307ccc539108e2cbc2a5a to your computer and use it in GitHub Desktop.
Output a Custom Taxonomy Loop of Terms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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