Skip to content

Instantly share code, notes, and snippets.

@neilgee neilgee/custom-tax.php
Last active Mar 19, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.