Invalid Taxonomy Error
-
Hello,
I have a custom taxonomy called “Recipe-Types” for a custom post type called “Recipes”. I am trying to use get_terms() OUTSIDE the loop on page template to list ALL the taxonomy terms used; however, when I tried to see what’s in the arrays return, there were no taxonomy terms, just “Invalid Taxonomy”. Here is the code I used to register the custom taxonomy in functions.php:
function create_taxonomies(){ $labels = array( 'name' => _x('Recipe Types', 'taxonomy general name'), 'singular_name' => _x('Recipe Type','taxonomy singular name'), 'search_items' => __('Search Recipe Types'), 'all_item' => __('All Recipe Types'), 'parent_item' => __('Parent Recipe Type'), 'parent_item_colon' => __('Parent Recipe Type:'), 'edit_item' => __('Edit Recipe Type'), 'update_item' => __('Update Recipe Type'), 'add_new_item' => __('Add New Recipe Type'), 'new_item_name' => __('New Recipe Type'), 'menu_name' => __('Recipe Type'), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'recipe-types'), ); register_taxonomy('recipe-type', array('recipes'), $args); } add_action('init','create_taxonomies');
And here is the code use on the page template OUTSIDE the loop:
$terms = get_terms('recipe-types', array( 'orderby'=>'name', 'order' =>'ASC' )); foreach ( $terms as $term ) { var_dump($term); //Shows "Invalid Taxonomy" echo '<br/>'; }
Is the problem in the functions or is get_terms() not used correctly?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Invalid Taxonomy Error’ is closed to new replies.