The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

WordPress doesn't recognize my custom taxonomy (14 posts)

  1. Miriam de Paula
    Posted 6 years ago #

    Hello everybody.

    I'm using WordPress 3.0.1 ...
    I created a Custom Post Type named "Products" and a Custom Taxonomy named "Catalog".

    Apparently everything works on the control panel. I see my new menu,
    add items to my catalog, all right.

    It seems that WordPress is not recognizing my new taxonomy.
    taxonomy_exists ('catalog') is returning false.

    When attempting to list the items in this new category (taxonomy), I get an error:

    $terms = get_terms ('catalog', 'hide_empty = 0');
    print_r ($terms);
    WP_Error Object ([errors] => Array ([invalid_taxonomy] => Array ([0]
    => Invalid Taxonomy)) [error_data] => Array ())

    Code I'm using to create the new taxonomy:

    add_action('init', 'new_taxonomies', 50);
    function new_taxonomies() ( 
    $labels = array(
    'name' => __('Product Categories'),
    'singular_name' => __('Product Category'),
    'search_items' => __('Search category'),
    'popular_items' => __('Popular category'),
    'all_items' => __('All Categories'),
    'parent_item' => __('Parent Category'),
    'parent_item_colon' => __('Parent Category:'),
    'edit_item' => __('Edit category'),
    'update_item' => __('Update Category'),
    'add_new_item' => __('Add new category'),
    'new_item_name' => __('New category name')
    register_taxonomy('catalog', array('shop'), array(
    'hierarchical' => true,
    'labels' => $labels, / / SEE this is the array $labels from
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array ('slug' => 'catalog')

    What did I do wrong?

    I thank those who can help me!

    Miriam de Paula (Drika)

    PS: excuse errors. I used Google Translator. I do not speak English

  2. Miriam de Paula
    Posted 6 years ago #

    Sorry, somebody can help me with this problem?

  3. Andrew Nacin
    Lead Developer
    Posted 6 years ago #

    You're likely calling taxonomy_exists() prior to your taxonomy being registered. Since you are registering it on the init hook, priority 50, you must wait until after that.

  4. mrmist
    Forum Janitor
    Posted 6 years ago #

    Moving you to the hacks forum, people who do this sort of coding more often frequent there.

  5. Christiann
    Posted 6 years ago #

    I'm not sure what's wrong with that code, but here is the code that eventually worked for me:

    function setup_product_post_type() {
    $labels = array(
        'name' => _x('Products', 'post type general name'),
        'singular_name' => _x('Product', 'post type singular name'),
        'add_new' => _x('Add New', 'book'),
        'add_new_item' => __('Add New Product'),
        'edit_item' => __('Edit Product'),
        'new_item' => __('New Product'),
        'view_item' => __('View Product'),
        'search_items' => __('Search Products'),
        'not_found' =>  __('No products found'),
        'not_found_in_trash' => __('No products found in Trash'),
        'parent_item_colon' => ''
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'menu_position' => null,
        'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields','revisions')
    register_taxonomy( 'producttype', 'products', array( 'hierarchical' => true, 'label' => __('Product Types') ) );
    register_taxonomy( 'designer', 'products', array( 'hierarchical' => true, 'label' => __('Designers') ) );
    register_taxonomy( 'producttag', 'products', array( 'hierarchical' => false, 'label' => __('Product Tags') ) ); 
    add_action('init', 'setup_product_post_type');

    Hope that's helpful.

  6. Christiann
    Posted 6 years ago #

    Yeah, I just read through your code again and am wondering if you registered a post type. As far as I know you need a post type to register a taxonomy. It seems like you're passing arguments to register_taxonomy that I would have passed to register_post_type.

  7. vteixeira
    Posted 6 years ago #

    Oi Miriam, o seu código está legal, só tem um erro logo no início:

    function new_taxonomies() (

    você colocou abrindo parenteses e deve ser chaves:

    function new_taxonomies() {

    Não esqueça de mudar no final do código também.

    Outra coisa, não sei porque você colocou prioridade 50, mas o idea seria 0:

    add_action('init', 'new_taxonomies', 0);

    Espero que agora funcione.

    Qualquer dúvida, pode falar comigo no gmail em victorhteixeira.

  8. Miriam de Paula
    Posted 6 years ago #

    Olá vteixeira, obrigada por responder.
    O erro na function new_taxonomies() ... aconteceu aqui na hora de digitar, mas no meu código está correto.

    E quanto a prioridade 50, eu havia encontrado um código assim na internet, mas eu já havia feito como o colega xiann falou, criando as custom taxonomies na sequencia do custom post e mesmo assim não deu certo.

    Estou tentando aqui ainda.. vamos ver no que vai dar.

    Obrigada a todos!


    Hello vteixeira, thanks for responding.
    The error in new_taxonomies function() ... happened here ..type error, but in my code is correct.

    What about the priority 50, I had found a code like that in
    internet, but I had done as Mr xiann said, creating the
    custom taxonomies in the wake of custom post and still did not

    I'm trying here yet .. let's see how it goes.

    Thank you for all!


  9. Miriam de Paula
    Posted 6 years ago #

    I did some tests...
    Localy (localhost), the xiann's code works ...but at the host server it doesn't work!

    Both, localhost and host server are runing WP 3.0 ...

    I'm really sad :-(

    Miriam de Paula

  10. Miriam de Paula
    Posted 6 years ago #

    I think I found the problem.
    I'll do some more tests and let you know if they really solve.

    Thank you!

  11. geemeetheway
    Posted 6 years ago #

    Hi! How did you solve that problem ? I'm stock there too.

  12. fvl2000
    Posted 5 years ago #

    If you check the existence of the custom taxonomy before it has been registered it returns false
    After your custom taxonomies have been registered you can use:

    add_action( 'init', 'check', 0 );
    function check() {
    if (taxonomy_exists('my_taxonomy')) {
    print "YES";
    else {
    print 'NO';

  13. niba
    Posted 5 years ago #

    Faced the same problem, bug in my case: i forgot to register the custom taxonomy in the front-end. I had this code:

    add_action("admin_init", "my_admin_init");
    function my_admin_init()
       register_taxonomy( ... );

    In addition to that, i had to add the register_taxonomy in the frontend init:

    add_action("init", "my_init");
    function my_init()
       register_taxonomy( ... );

    Trivial fault for advanced users, but maybe helpfull for others ;)

  14. Surabi Santosh
    Posted 5 years ago #

    Had same issue, but found that I was executing that code only for admin login... it was inside if(is_admin()) ... placing it outside works.

Topic Closed

This topic has been closed to new replies.

About this Topic