hello again from a far far away place.
you know i`m trying to list all of terms from a custom taxonomy , when i use below code :
$terms = get_terms($taxonomy , 'hide_empty=0');
print_r($terms);
$count = count($terms);
if ( $count > 0 ){
echo "<ul>";
foreach ( $terms as $term ) {
echo "<li>" . $term->name . "</li>";
}
echo "</ul>";
wp return a crazy error that says : INVALID TAXONOMY :
WP_Error Object
(
[errors] => Array
(
[invalid_taxonomy] => Array
(
[0] => Invalid Taxonomy
)
)
[error_data] => Array
(
)
)
it is very interesting that you know , when i use above code in single.php, i have not see any error and it works fine.
somebody please help me !
Resolved
I am trying to use:
to use my admin theme option and face same problem when using:
But now its resolved using:
get_terms return invalid taxonomy error because:
you have a custom taxonomy registered in the “init” hook
so in the wp-admin it doesn´t work -> your taxonomy is registered after you call “get_term”
https://wordpress.stackexchange.com/questions/13480/get-terms-return-errors/13482#13482
Oh my … i solve this by a crazy solution temporary.look below :
As you can see i use a query, but i cant apply this plugin to my programming team.i still awaiting for a correct solution/usage for get_terms function in wordpress plugins.
regards.
Nothing really to add but to make it clear:
get_terms()
doesn’t work in “admin_init” action hook!I did like bizzr3. Just put my code here because I was a bit confuse with bizzr3’s code:
then just call
load_terms()
in your “admin_init” function:and thanks, works like a charm.
I know I’m late to the party.
To optimise bizzr3’s code just a bit; You should use the $wpdb object properties for your table names, as “wp_” is just the default but it could change from site to site. Using the object property you make sure it should work for other WordPress sites as well if they have a different table prefix.
Also changed the single quotes to double quotes to use {$variables}