Created
September 1, 2017 08:23
-
-
Save celticwebdesign/574b011c3e6f7295e32e0007643d5337 to your computer and use it in GitHub Desktop.
WordPress - Get All Categories
This file contains hidden or 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
| 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