WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom post type called cars. There is a taxonomy brands.

I have a template single-cars.php and I'd like to add a link to the brand page(The category). Assume I'm on the page of the post Passat 2013. The brand is Volkswagen. I'd like to show the permalink of the brand Volkswagen.

My setup: functions.php

$labelsCars = array(
    'name' => 'Cars',
    'singular_name' => 'Car',
    'menu_name' => 'Cars',
    'add_new_item' => 'Add New Car',
    'edit_item' => 'Edit Car',
    'new_item' => 'New Car',
    'view_item' => 'View Car',
    'not_found' => 'No Cars Found'

$argsCars = array(
  'labels' => $labelsCars,
  'public' => true,
  'publicly_queryable' => true,
  'show_ui' => true, 
  'show_in_menu' => true, 
  'query_var' => true,
  'rewrite' => true,
  'capability_type' => 'post',
  'has_archive' => true, 
  'hierarchical' => false,
  'menu_position' => null,
  'supports' => array('title','editor','page-attributes','thumbnail'),
  'exclude_from_search' => true,
  'taxonomies' => array('brands')

$labels = array(
  'name' => 'Brands',
  'singular_name' => 'Brand',
  'search_items' => 'Search Brands',
  'all_items' => 'All Brands',
  'edit_item' => 'Edit Brand', 
  'update_item' => 'Update Brand',
  'add_new_item' => 'Add New Brand',
  'new_item_name' => 'New Brand',
  'menu_name' => 'Brands'

register_taxonomy('brands',array('cars'), array(
   'labels' => $labels, 
   'hierarchical' => true,
   'show_ui' => true,
   'query_var' => true,
   'rewrite' => array( 'slug' => 'brands' ),
   'show_in_nav_menus' => true


<?php get_header(); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php $content = get_the_excerpt(); ?>
<?php the_content() ?>
<?php echo '<pre>'.print_r(get_the_category($post->ID), 1).'</pre>'; ?>
<?php endwhile; // end of the loop. ?>
<?php get_footer(); ?>

The page single-cars.php shows an empty array, while the $post var is filled with data.

I've been searching through the docs and with Google and ofcourse also here, but I didn't find anything..

What should I do to fix this?

share|improve this question
up vote 4 down vote accepted

get_the_category() only works with the default taxonomy, per the Codex page; you probably need to use get_the_terms() instead.

So you'd replace your get_the_category() call with get_the_terms( $post->ID, 'brands' );, if I'm not mistaken.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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