Search code examples
wordpressgettaxonomy

get_terms return errors


Hi when i try to get_terms(); in theme options via this code

$catalogs_terms = get_terms( 'catalogs' );
   $mycatalogs = array( -1 => 'Select a catalog' );
   if ( $catalogs_terms ) {
      foreach ( $catalogs_terms as $catalog_term ) {
         $mycatalogs[$catalog_term->term_id] = $catalog_term->name;
      }
   }

return empty but this code is working fine every where in pages etc. when i try to print_r( $catalogs_terms ) output i am getting errors

Array ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid Taxonomy ) ) [error_data] => Array ( ) )

i don't understand where am i wrong? my function for register taxonomy

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

function my_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        'name' => _x( 'Catalogs', 'taxonomy general name' ),
        'singular_name' => _x( 'Catalog', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Catalogs', 'mytextdomain' ),
        'all_items' => __( 'All Catalogs', 'mytextdomain' ),
        'parent_item' => __( 'Parent Catalog', 'mytextdomain' ),
        'parent_item_colon' => __( 'Parent Catalog:', 'mytextdomain' ),
        'edit_item' => __( 'Edit Catalog', 'mytextdomain' ), 
        'update_item' => __( 'Update Catalog', 'mytextdomain' ),
        'add_new_item' => __( 'Add New Catalog', 'mytextdomain' ),
        'new_item_name' => __( 'New Catalog Name', 'mytextdomain' ),
        'menu_name' => __( 'Catalogs', 'mytextdomain' ),
    );  

    // register catalogs hierarchical (like categories)
    register_taxonomy( 'catalogs',
        array( 'news' ),
        array( 'hierarchical' => true,
            'labels' => $labels,
            'show_ui' => true,
            'public' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'catalogs' )
        )
    );
}

Solution

  • I have solved this with help of t31os

    you can finde more here