Development,  WordPress

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:

$my_terms = get_terms( array(
	'taxonomy' => 'my_taxonomy',
	'hide_empty' => false,
	'parent' => 0,
) );

[postad1]
And this is ok, for WordPress 4.5. For older WordPresses and to keep compatibility, use this:

$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.
[postad2]

One Comment

Leave a Reply

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