The issue I've encountered is that when I try to call the get_terms() function inside the custom walker, it returns "Invalid taxonomy".
What I've tried
I read up about it,know for a fact that the taxonomy is registered and I think it's due tothat there are terms in the database. It seems like the get_terms() is getting called before init when it's invoked in the walker class. Since the taxonomy gets registered on init, the taxonomy is invalid when the walker class is calling get_terms();
What I've tried
So I tried to lift out the get_terms() function from the class and do the following:
I even tried making the variable global, but it still doesn't return any terms, and throws an error for the taxonomy being invalid. But aA var_dump on that variable still gives me "Invalid taxonomy" error. So I read on, and saw in a comment at the codex (on the Walker_Nav_menu class page) that I need to use static functions, and did this inside the custom walker class:
And thatThat var_dump runs as it should but still returns the "Invalid taxonomy" error.
Edit
I know for a fact thattried changing my custom taxonomy to the built-in taxonomy is registered'category' and that there are terms in the databasethen my function works. Using 'mytax' it still gives me invalid taxonomy.
The custom taxonomy is registered with
add_action( 'init', 'custom_register_taxonomies');
I am now fairly certain that this issue is due to the wp_nav_menu
call coming earlier than the registration of my custom taxonomy.
The questionquestions
So what am I missing hereIs it safe to register the custom taxonomies earlier than on init
? I'm including my
Am I right in using static functions in the custom walker class, if anyone would likeas described above?
Would it improve anything to show me how I would best go aboutdelay the wp_nav_menu
call, by calling it from a custom location in my child theme. Rather than letting the get_terms() function inside thisparent theme call it, and adapting my walker class. and/or taxonomy registration function?
Am I on the right track here or am I missing something else?
I'm including my custom walker below. Any tips are greatly appreciated.