• Resolved sarscott

    (@sarscott)


    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:
    It goes Manufacture > Model > Chassis Prefix

    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?

    This is the closest thing I found is this:
    Display Categories Assigned to a Post
    but I’m not sure how I’d specify if i wanted to echo the parent or child etc

    Many thanks

    S

Viewing 1 replies (of 1 total)
  • Thread Starter sarscott

    (@sarscott)

    I never seem to get a reply on the WordPress forums…

    I managed to solve it by using this code. Maybe it will help someone else:

    <?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;
    	}
    ?>
Viewing 1 replies (of 1 total)

The topic ‘Get current post taxonomy (category)’ is closed to new replies.