#1
The function call:
<?php gomo_get_all_terrains(); ?>
The function:
<?php if ( ! function_exists( 'gomo_get_all_terrains' ) ) :
function gomo_get_all_terrains() {
$args = array(
'taxonomy' => 'terrain',
'hide_empty' => true,
);
get_categories($args);
$categories = get_categories( $args );
$items = array();
foreach($categories as $category) {
$items[] = sprintf( '<a href="%1$s">%2$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_html( $category->name )
);
}
echo implode(", ", $items);
}
endif; ?>
#2
The function call with variable:
<?php gomo_get_all_tags('terrain'); ?>
The function:
<?php
if ( ! function_exists( 'gomo_get_all_tags' ) ) :
function gomo_get_all_tags($atts) {
$args = array(
'taxonomy' => $atts,
'hide_empty' => true,
);
get_categories($args);
$categories = get_categories( $args );
$items = array();
foreach($categories as $category) {
$items[] = sprintf( '<a href="%1$s">%2$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_html( $category->name )
);
}
echo implode(", ", $items);
}
endif;
?>
#3
Adding a shortcode to option #2:
<?php
add_shortcode('gomo-tags', 'gomo_get_all_tags');
?>
The shorcode
[gomo-tags tags="terrain"]
or
<?php
do_shortcode('[gomo-tags tags="terrain"]');
?>