0

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 :)

  • 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ż Jun 12 at 20:18
  • Cześć, Krzysztof:) I mean singular_name of custom taxonomy, my mistake :) – Piotr Milecki Jun 12 at 20:20
0

As 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>' );
} ?>
0

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.