I am trying to use get_the_category() in my theme's functions.php file. When I print the array as seen below, I get an empty array. This code works just fine in the templates.
$category = get_the_category();
print_r($category);
Is there a trick that enables the use of template tags in this file?
This code works for me. Must be used in The Loop!!!. Test in the the index.php, using the WordPress Default theme:
<?php my_get_cat(); ?>
and this in the functions.php file:
function my_get_cat() {
$category = get_the_category();
print_r($category);
}
Sorry for not being more clear. I am actually trying to get an array of categories in the functions.php file for use in a separate function. For some reason I can't create an array of categories in functions.php while using get_the_category(). Possibly because the SQL data or get_the_category() functions are not referenced in the functions.php file?
Is there a SQL command or another function similar to get_the_category() that would work and accomplish this task in functions.php?
Thanks for your help!
Thank you - that is exactly what I am looking for!