• 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
    above
    '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

Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter Miriam de Paula

    (@drikasantossp)

    Sorry, somebody can help me with this problem?

    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.

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

    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_post_type('products',$args);
    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.

    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.

    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.

    Thread Starter Miriam de Paula

    (@drikasantossp)

    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!

    Miriam

    TRANSLATED FROM GOOGLE:
    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
    work.

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

    Thank you for all!

    Miriam

    Thread Starter Miriam de Paula

    (@drikasantossp)

    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

    Thread Starter Miriam de Paula

    (@drikasantossp)

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

    Thank you!

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

    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’;
    }
    }

    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 ??

    Surabi Santosh

    (@santoshsurabigmailcom)

    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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘WordPress doesn't recognize my custom taxonomy’ is closed to new replies.