EDIT
Since I missunderstood your question at first, here’s the update that should do what you want.
$taxonomies = get_object_taxonomies( 'my_post_type', 'object' );
foreach($taxonomies as $tax){
echo $tax->labels->singular_name;
}
Basically, you need to specify to the get_object_taxonomies
function that you want an object to be returned.
In your function, I’m not sure where the $args
come from and put as is, it can’t work.
Finally, use the correct syntax to work with an object. You access the object property with ->
ORIGINAL
I believe you are looking for the get_terms()
function. So you would have something like this:
// Retrieve the taxonomies for your custom post type
$cpt_taxes = get_object_taxonomies( 'my_post_type', 'object' );
// Build an array of taxonomies slugs to be used in our $args array below to filter only taxes we need.
foreach( $cpt_taxes as $cpt_tax ){
$taxonomies[] = $cpt_tax->name;
}
// Supply our $args array for the get_terms() function with our newly created $taxonomies array.
$args = array(
'taxonomy' => $taxonomies,
'hide_empty' => false,
);
$terms = get_terms( $args );
// Go over the results of the get_terms function and echo each term name.
foreach( $terms as $term ){
echo $term->name;
}