Wordpress - Why is my working Custom Taxonomy not in get_taxonomies array?
The Invalid Taxonomy
error will be raised by the function get_terms()
. You're registring your taxonomy on the init
action hook. Therefore you have to call your get_terms()
function on the same or a later hook.
Try this snippet. It should display all term names of your taxonomy, regardless if the term is empty.
add_action('init', 'wpse29164_registerTaxonomy');
function wpse29164_registerTaxonomy() {
$args = array(
'hierarchical' => true,
'label' => 'Double IPAs',
'show_ui' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'double-ipa'
),
'singular_label' => 'Double IPA'
);
register_taxonomy('double-ipa', array('post', 'page'), $args);
$terms = get_terms('double-ipa', array('hide_empty' => false));
foreach ($terms as $term) {
echo $term->name;
}
}
You're looking to use get_terms() before 'Init' action hook.
Here's the order of the hooks run in a typical request:
muplugins_loaded
registered_taxonomy
registered_post_type
plugins_loaded
sanitize_comment_cookies
setup_theme
load_textdomain
after_setup_theme
auth_cookie_malformed
auth_cookie_valid
set_current_user
**init**
widgets_init
register_sidebar
wp_register_sidebar_widget
wp_default_scripts
wp_default_stypes
admin_bar_init
add_admin_bar_menus
wp_loaded
parse_request
send_headers
parse_query
pre_get_posts
posts_selection
wp
template_redirect
get_header
wp_head
wp_enqueue_scripts
wp_print_styles
wp_print_scripts