What I want to do:
I have four custom post types. I only want to use one, which I can do like this: $current_posttype = get_post_type( $post->ID ); // get current post type
.
Next up, I want to loop through all the custom taxonomies that are attached to that custom post type. So, for example:
custom post type: movies
custom taxonomy 1: genre
custom taxonomy 2: rating
custom taxonomy 3: year
and so on..
I want to output the following (for the current post):
genre: Western
rating: 4
year: 2000
What I do know is that I can use the following code to output all terms of a custom taxonomy.
// Get terms for post
$terms = get_the_terms( $post->ID , 'genre' );
// Loop over each item since it's an array
if ( $terms != null ){
foreach( $terms as $term ) {
// Print the name method from $term which is an OBJECT
if ( $term->name != null ) {
?></br><?php print $term->name ;
// Get rid of the other data stored in the object, since it's not needed
}
else {
}
unset($term);
} }
What I don't know is how to loop over this, with a foreach loop. I can't figure it out. Any help or suggestions? Thanks.