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 am encountering a weird error when working with custom taxonomies. I am trying to get the name of categories of a custom taxonomy:

$terms = get_terms('taxonomy_name');

foreach ($terms as $term) {

    $option = $term->name;
    echo $option;

I'm not using the code into a template file, like page.php. I use it in functions.php but after the function which created the taxonomy. The code works fine if the taxonomy is a standard one like "category"(which displays regular post categories) but it's not working with custom ones.

I already tried to use $option = $term['name']; but with no luck. The error I get on this one is "Undefined index: name".

Any answer will be much appreciated!

Thank you! Madalin

share|improve this question
Based on the error you wrote, there must be some other code that you didn't mentioned in the question & which must be causing the problem, can you add your full function to the question? – Mridul Aggarwal Nov 21 '12 at 8:48
@MridulAggarwal I`m trying to use custom taxonomies inside the admin panel. I want to generate the list of taxonomy names of a custom post type and to show them inside a meta box on wordpress pages . When someone creates a page which is using the custom template related to the custom post type, the meta box should appear with categories related to that custom post type. – Madalin Nov 21 '12 at 9:25
What i mean is that the code currently in question is correct. The problem is due to some other nearby code. Can you add the rest of the code? – Mridul Aggarwal Nov 21 '12 at 9:46
@MridulAggarwal I suppose the code related to this issue is the one which registered the taxonomy: pastebin.com/Q0fpp7pn – Madalin Nov 21 '12 at 9:57
nope. Either the $terms variable is being altered somewhere above foreach or the $term is being altered inside foreach, otherwise the error message would have been different. – Mridul Aggarwal Nov 21 '12 at 10:01
 get_terms( 'taxonomy_name', array(
        'hide_empty' => 0) );


share|improve this answer
Hi, unfortunately, this solution is not working. Thanks anyway! – Madalin Nov 21 '12 at 9:16
This is not answer, just a code snippet. Please add an explanation. See How to Answer Thanks. – toscho Nov 21 '12 at 9:41

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.