So. I created a custom WordPress taxonomy. And I have multiple posts that use that taxonomy with various terms under this taxonomy. What I'm trying to get WordPress to do is spit out all the taxonomy terms from all the posts. I'm going to stick each of them inside a rel="" tag so I can get a little fancy with jQuery.
I accomplished this with plain old WordPress tags like this:
<?php
$posttags = get_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo '<label><input type="checkbox" rel="' . $tag->slug . '">' . $tag->name .
'</label>';
}
}
?>
It works perfectly. Makes a checkbox and label for each tag. But now I need these custom taxonomy terms instead.
I've been fiddling with:
$categories = get_terms('Year-taxonomy', 'orderby=name&hide_empty=0');
$cats = object_to_array($categories);
Not working so far. Am I on the right track?
Not well versed with the WordPress Codex, but managed to figure it out.
First off there's the function:
function get_custom_terms($taxonomies, $args){
$args = array('orderby'=>'asc','hide_empty'=>true);
$custom_terms = get_terms(array($taxonomies), $args);
foreach($custom_terms as $term){
echo 'Term slug: ' . $term->slug . ' Term Name: ' . $term->name;
}
}
Then the function call wherever need:
<?php get_custom_terms('your_custom_taxonomy_name'); ?>