WP get_terms() returns error on admin side

314 Views Asked by At

This one might be a simple question, but it's driving me nuts :)

I'm trying to make an admin settings page on the wp-admin side for which I need to get all the values of a certain category.

This is part of my test code:

$terms = get_terms( array(
    'taxonomy' => 'my-category',
    'hide_empty' => false,
) );
echo '<pre>';
var_dump($terms);
echo '</pre>';

But this returns an error. Something like "invalid taxonomy". When I leave the 'taxonomy' arg from get_terms() it returns all the terms successfully. ( but of course I need to filter it by my tax term.

Anyone knows what's up? :)

Any help would be highly appreciated.

1

There are 1 best solutions below

7
On

Please try this code

get_terms(  array('taxonomy' => 'any_taxonomy','hide_empty' => false) );

https://developer.wordpress.org/reference/functions/get_terms/