Reputation: 17
Having problems solving a basic (but new to me) custom taxonomy issue--I have used the get_the_category() function quite a bit in my theme. Namely as a "search and replace" if you will
foreach((get_the_category()) as $category) pulls the category of "state" and is used:
/images/States/' . $category->cat_name . '.png
(category= colorado, then it pulls colorado.png)
Easy. Great. but....I would like to do this same thing with a custom taxonomy but can't figure out how to get it to work.
I have a Custom Post Type of "City Pages" (city_pages) For those pages I have created a taxonomy of "State" (state) (these have to be different than the "categories" of state)
I have looked, I have researched and I cannot figure out how to do this. I know there are similar questions/problems out there but I have not been able to put 2 and 2 together in order to get this to work.
Upvotes: 1
Views: 3486
Reputation: 618
I think this is what you want: http://codex.wordpress.org/Function_Reference/get_terms
So it woud be something along the lines of:
<?php
$states = get_terms( 'state' );
foreach( $states as $state ) {
echo '<img src="./images/States/' . $state->name . '.png">';
}
?>
Upvotes: 0