I've got a custom post type with multiple custom taxonomies + metaboxes. I've used multiple approaches from the codex and other on line resources but none seem to work. I basically want to display the current posts taxonomy values below the title on each custom post's page. This is what I have so far...
In functions.php:
function discography_album_label() {
$labels = array(
'name' => _x( 'Labels', 'taxonomy general name' ),
'singular_name' => _x( 'Label', 'taxonomy singular name' ),
'search_items' => __( 'Search Labels' ),
'all_items' => __( 'All Labels' ),
'parent_item' => __( 'Parent Label' ),
'parent_item_colon' => __( 'Parent Label:' ),
'edit_item' => __( 'Edit Label' ),
'update_item' => __( 'Update Label' ),
'add_new_item' => __( 'Add New Label' ),
'new_item_name' => __( 'New Label' ),
'menu_name' => __( 'Labels' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'rewrite' => array( 'slug' => 'label' ),
);
register_taxonomy( 'discography_album_label', 'discography', $args );
}
add_action( 'init', 'discography_album_label', 0 );
In single-discography.php
$genreTax = get_taxonomies( '', 'names' );
$terms = wp_get_post_terms($post->ID, $genreTax, array("fields" => "names", "orderby" => "type"));
<p><?php print_r($terms);?></p>
However all this is outputting is:
Array ( [0] => Ska [1] => Reggae [2] => Record Label )
...which doesn't really help as it's the values for the "Labels" and and the "Genres" taxonomies (with no way of differentiating which is from which). How can I get just the value for one of these taxonomies?
get_the_terms( $post->ID, 'discography_album_label' )
$albumGenres = get_the_terms( $post->ID, 'discography_album_label' );
<?php print_r($albumGenres);?>
I see:Array ( [17] => stdClass Object ( [term_id] => 17 [name] => Record Label [slug] => record-label [term_group] => 0 [term_taxonomy_id] => 17 [taxonomy] => discography_album_label [description] => [parent] => 0 [count] => 1 [object_id] => 43 [filter] => raw ) )
How can I just get thename
value? I tried<?php print_r($albumGenres->name);?>
but nothingget_the_terms()
and then grab thename
property.foreach ( $albumGenres as $albumGenre ) { echo $albunGenre->name; }