0
votes

I've got so confused between all the different terms for taxonomy when reading up on wordpress.

I have a custom post type of car, I have a custom taxonomy of car manufactures. I would simply like to output/echo the manufacturer on the single post page.

Car manufactures taxonomy example:

  • Honda
    • Civic
      • EK4
      • EK9
    • Integra
      • DC2

etc...

What code should I use so echo the taxonomy? Looking at the above example, is there a way to echo only the parent (Honda) or child (either Civic or EK4) if I choose to?

Many thanks

S

1
Thanks for your reply, this codex.wordpress.org/Function_Reference/… seems closer to what I'd like to do but I'm not sure how I'd specify if i wanted the parent, child etc - Steviehype

1 Answers

1
votes

Here's what I did in the end in case it helps anyone else.

In the places where I need to show the Manufacture I would print the name of $terms object 0, if I need the Model I'd print the name of $terms object 1 etc...

<?php
    //Get the posts taxonomy details.
    $taxonomy = 'car_manufacturers';
    $terms = wp_get_object_terms( $post->ID, $taxonomy, array('orderby'=>'term_order') );

    //If terms has something in it, echo what I need.
    // 0 = Manufacture
    // 1 = Model
    // 2 = Chassis Prefix
    if ( !empty( $terms ) && !is_wp_error( $terms ) ) {
        echo $terms[1]->name;
    }
?>