I'm displaying list of term from each taxonomy assigned to custom post:
<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {
the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . SINGULAR_NAME . ': </strong> ', ", ", '</span>' );
} ?>
but here, in SINGULAR_NAME I would like to display the singular_name of custom taxonomy.
I was trying this:
<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {
$term_name = $taxonomy->labels->singular_name;
the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . $term_name . ': </strong> ', ", ", '</span>' );
} ?>
What I want to do is show all terms, separately for each taxonomy, but before each list I want to display taxonomy name (singular_name).
How to do that correctly?
Thanks :)
I'm displaying list of term from each taxonomy assigned to custom post:
<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {
the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . SINGULAR_NAME . ': </strong> ', ", ", '</span>' );
} ?>
but here, in SINGULAR_NAME I would like to display the singular_name of custom taxonomy.
I was trying this:
<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {
$term_name = $taxonomy->labels->singular_name;
the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . $term_name . ': </strong> ', ", ", '</span>' );
} ?>
What I want to do is show all terms, separately for each taxonomy, but before each list I want to display taxonomy name (singular_name).
How to do that correctly?
Thanks :)
Share Improve this question edited Jun 12, 2019 at 20:20 Piotr Milecki asked Jun 12, 2019 at 19:55 Piotr MileckiPiotr Milecki 253 bronze badges 2- Hi Piotr, what do you mean by "singular_name of CPT"? What exactly do you want to print? Could you update your question and add the effect you want to achieve? – Krzysiek Dróżdż Commented Jun 12, 2019 at 20:18
- Cześć, Krzysztof:) I mean singular_name of custom taxonomy, my mistake :) – Piotr Milecki Commented Jun 12, 2019 at 20:20
2 Answers
Reset to default 0As far as I'm aware, your question has been answered here.
You're getting the singular_name correctly, all you need to do is echo it.
<?php $taxonomies = get_object_taxonomies( $post );
foreach ( $taxonomies as $taxonomy ) {
$term_name = $taxonomy->labels->singular_name;
echo $term_name;
the_terms( $post->ID, $taxonomy, '<span class="e-article__category__item"><strong>' . $term_name . ': </strong> ', ", ", '</span>' );
} ?>
I finally get this done:
<?php $taxonomies = get_object_taxonomies( $post, 'objects' );
foreach ( $taxonomies as $taxonomy ) {
$tax_name = $taxonomy->labels->singular_name;
the_terms( $post->ID, $taxonomy->name, '<span class="e-article__category__item"><strong>' . $tax_name . ': </strong> ', ", ", '</span>' );
} ?>
thanks :)