get_terms() returns Trying to get property of non-object error for custom taxonomy

Created custom post type and now I’m trying to create a custom taxonomy. Once I create it and try to access it with get_terms() I get an error of non-object. Var_dump is giving me an empty array object(WP_Error)[1279]
public ‘errors’ =>
array (size=1)
‘invalid_taxonomy’ =>
array (size=1)
0 => string ‘Invalid taxonomy.’ (length=17)
public ‘error_data’ =>
array (size=0)
empty

Here is the code:

$use_case_categories = get_terms(‘type’);
var_dump($use_case_categories); die();

function custom_taxonomies() {
$labels = array(
‘name’ => ‘Types’,
‘singular_name’ => ‘Type’,
‘search_items’ => ‘Search Types’,
‘all_items’ => ‘All Types’,
‘parent_item’ => ‘Parent Type’,
‘parent_item_colon’ => ‘Parent Type:’,
‘edit_item’ => ‘Edit Type’,
‘update_item’ => ‘Update Type’,
‘add_new_item’ => ‘Add New Custom Type’,
‘new_item_name’ => ‘New Type Name’,
‘menu_name’ => ‘Type’
);
$args = array(
‘hierarchical’ => true,
‘labels’ => $labels,
‘show_ui’ => true,
‘show_admin_column’ => true,
‘query_var’ => true,
‘rewrite’ => array(‘slug’=>’type’)
);

register_taxonomy(‘type’, array(‘use_cases’), $args);
}

add_action(‘init’, ‘custom_taxonomies’);

Read more here:: get_terms() returns Trying to get property of non-object error for custom taxonomy

Leave a Reply

Your email address will not be published. Required fields are marked *