admin管理员组文章数量:1318570
I am trying to get category names for the ones that are available in permalink. e.g. I have the following permalink structure.
abc/product-category/category-1/category-2/
Where as category-1 and category-2 both are categories. When I try $wp_query->get_queried_object()
, it just returns info related to category-2. How can I get details of category-1 using any existing WordPress functions?
I am trying to get category names for the ones that are available in permalink. e.g. I have the following permalink structure.
abc/product-category/category-1/category-2/
Where as category-1 and category-2 both are categories. When I try $wp_query->get_queried_object()
, it just returns info related to category-2. How can I get details of category-1 using any existing WordPress functions?
1 Answer
Reset to default 0The function get_category_parents
will get you a string of the parent categories given the ID of a child category. So, like this:
$cat = $wp_query->get_queried_object();
$catid = $cat->cat_ID;
$parentcats = get_category_parents ($catid, false, '|', false);
This will give you something like category1|category2|category3
. Follow the link above to see what other options you have. If you want to do more complicated stuff, you could split the string using explode
.
本文标签: categoriesGet multiple category names from permalink
版权声明:本文标题:categories - Get multiple category names from permalink 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742047651a2417883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论