how do I get category object from category name? I can't seem to find a function that does that. if the category name is "my category". I tried running:
get_category('my category);
but it just returns 0.
You can use get_term_by function.
$category = get_term_by('name', 'my category', 'category')
Reference: https://codex.wordpress.org/Function_Reference/get_term_by
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With