Php 如何从类别名称中获取类别对象

Php 如何从类别名称中获取类别对象,php,wordpress,Php,Wordpress,如何从类别名称中获取类别对象?我似乎找不到这样的函数。如果类别名称为“我的类别”。我试着跑步: get_category('my category); 但它只返回0。您可以使用get\u term\u by函数 $category = get_term_by('name', 'my category', 'category') 参考资料:我想要按名称获取分类('slug',获取查询变量('term'),获取查询变量('taxonomy'));echo$term->name?

如何从类别名称中获取类别对象?我似乎找不到这样的函数。如果类别名称为“我的类别”。我试着跑步:

get_category('my category);

但它只返回0。

您可以使用
get\u term\u by
函数

$category = get_term_by('name', 'my category', 'category')

参考资料:

我想要按名称获取分类('slug',获取查询变量('term'),获取查询变量('taxonomy'));echo$term->name