Get_terms and invalid taxonomy
Funny thing, I was building application and I used get_terms
to get list of certain taxonomies. It all works well on my localhost… where I got WordPress 4.5 installed. I’ve uploaded this code onto client’s staging server and…
Ba Dum Tss!
Yeah, I got “Invalid taxonomy” error. What the hell? – I asked myself. And then I answered myself – oh, yeah, client has WordPress 4.4… and I used this construction:
1 2 3 4 5 |
$my_terms = get_terms( array( 'taxonomy' => 'my_taxonomy', 'hide_empty' => false, 'parent' => 0, ) ); |
And this is ok, for WordPress 4.5. For older WordPresses and to keep compatibility, use this:
1 2 3 4 5 |
$my_terms = get_terms( 'my_taxonomy', array( 'taxonomy' => 'my_taxonomy', 'hide_empty' => false, 'parent' => 0, ) ); |
This one will work for WordPress 4.5 and for older ones, too.
One Comment
Viktor Balogh
Thanks, you just saved me a bunch of time ^^