0

I try to register my taxonomy in my plugin and use it after. So far I have done:

function custom_taxonomy() {
    $labels = array(
        ...
    );
    $args = array(
        ...
    );
    register_taxonomy( 'taxonomy', array( 'oferta' ), $args );
}
add_action( 'init', 'custom_taxonomy_miasta', 0 );

So as you can see I run it from init with priority 0. After that I trying to call it from function and code, but it always gives me a Invalid taxonomy error.

Of course, there is no other error in code, cause when I try to get taxonomy values with init with priority lower than taxonomy, it works, but I need to recive value from my functions, init doesn't fit for me.

As far as I found there is a list in correct order how is it run:

muplugins_loaded
registered_taxonomy
registered_post_type
plugins_loaded <- here is my plugin loaded !!!!!!
sanitize_comment_cookies
setup_theme
load_textdomain
after_setup_theme
auth_cookie_malformed
auth_cookie_valid
set_current_user
init <- here I define taxonomy !!!!!!
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

I tried to define taxonomy in registered_taxonomy, but then my XAMPP wasn't loading page at all. I tried few tricks, but it doesn't work either.

And still, if I define it before plugins_loaded will it work? Because I register taxonomy inside plugin anyway...

Anyway, I need to have access to those taxonomies from plugin and dunno how to do it. I'd love to get some help ^^

EDIT 1: I explained why I get an error and what operation would fix it, but I don't know how to write it :) But as you wish, code with "error":

 function return_taxonomy_function() {
    $args = array(
        'hide_empty' => 0,
        'fields' => 'ids',
        'search'  => '',
    );
    $tax = new rav_search( array() );

    $tax->load_taxonomy('taxonomy', $args);
    $ret = $tax->taxonomy['taxonomy'];
    print_r($ret);
    return $ret;
 }

 add_action( 'init', 'return_taxonomy_function', 50 );

 add_action( 'return_taxonomy', 'return_taxonomy_function', 50 );

 print_r(do_action('return_taxonomy'));

 print_r(return_taxonomy_function())

After function I run few tests and only one works is init, but I can't get any value to my code from this (because it is called much later than my code). $tax->load_taxonomy('miasto', $args); is kinda allias to get_terms().

What I need to do is simple $value = return_taxonomy_function(); working, without error.

  • "After that I trying to call it from function and code". where? when? add the code that gives you invalid taxonomy error. there is no valid reason why it needs to be registered earlier, the error is within the code you are trying to access it from. – Milo Jul 17 '15 at 17:24
  • Done, still looking for help. – RaV Jul 17 '15 at 21:09
  • why does your code have to run before init when the taxonomy is registered? – Milo Jul 17 '15 at 21:40
  • Because plugin uses taxonomy names and values. So I need to get values from get_term into my plugin. – RaV Jul 17 '15 at 22:01
  • yes, but why do you need to get them before init? – Milo Jul 17 '15 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.