Skip to content

Instantly share code, notes, and snippets.

@celticwebdesign
Created September 1, 2017 08:23
Show Gist options
  • Select an option

  • Save celticwebdesign/574b011c3e6f7295e32e0007643d5337 to your computer and use it in GitHub Desktop.

Select an option

Save celticwebdesign/574b011c3e6f7295e32e0007643d5337 to your computer and use it in GitHub Desktop.
WordPress - Get All Categories
function get_all_categories($taxonomy) {
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
)
);
if ( $terms && ! is_wp_error( $terms ) ) :
$output = "";
$draught_links = array();
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
$draught_links[] = $term->name;
$output .= "<span>
<a href='".$term_link."'>".$term->name."</a>
</span>";
}
$on_draught = join( " ", $draught_links );
return $output;
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment