0

So, I have to show the taxonomies that are present on a custom post, with their terms.

I have some taxonomies (around 10) and all of them have a few terms. Eacho post can have any number of taxonomies, but all of them will have only one term selected.

I need to show a list of the terms that are present on the post and in place of the taxonomy name, I need to show a custom name.

For example: Taxonomy: Bikes Term: BTT

Instead of showing something like "Bikes : BTT", I need to show something like "Bicycle : BTT".

I have a code that gives me the taxonomy and the term, but couldn't think of the best way to 'change' that taxonomy for a custom name.

Here is the code so far:

//creates the array to format the list of taxonomies
$args = array(
    'template' => __( '%s: %l.' ), 
    'term_template' => '<a href="%1$s">%2$s</a>',
);
//creates the array to receive all the taxonomies
$taxList = get_the_taxonomies( $post->ID, $args );
//shows every taxonomy separately
foreach ($taxList as $taxItem) {
    echo $taxItem;
endforeach;

1 Answer 1

0

Perhaps you can change the label of your taxonomy, as seen on the Function Reference

Somewhere in your code, there must be something like

register_taxonomy("bikes", "post", [
  // ...
]);

you can change it to

register_taxonomy("bikes", "post", [
  "label" => "Bicycle"
]);

PLEASE NOTE that this part is the definition of the taxonomy itself. Changing it means changing the taxonomy itself and it can affect other parts of your project.

1
  • Can't do that, because I have taxonomies with repeated names, like: Bikes Models, Accessories Models, etc. And they need to look like 'Models'. Commented Nov 24, 2017 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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