admin管理员组文章数量:1422453
Currently I am able to get all categories but I want only few categories to display based on name or slug for example.
$categories = get_categories('accessibility','wcag', 'abc');
is this possible ?
Currently I am able to get all categories but I want only few categories to display based on name or slug for example.
$categories = get_categories('accessibility','wcag', 'abc');
is this possible ?
Share Improve this question asked Jun 25, 2019 at 13:18 Abhilash NarayanAbhilash Narayan 34 bronze badges 3- What do you mean by "few categories to display"? Do you want posts from those categories, or just the term objects themselves? – Nathan Powell Commented Jun 25, 2019 at 13:40
- just term objects – Abhilash Narayan Commented Jun 25, 2019 at 14:00
- What criteria? You need to be specific. – Jacob Peattie Commented Jun 25, 2019 at 14:04
1 Answer
Reset to default 1If you are looking for specific term objects from the term slugs, from a specific taxonomy, I think new WP_Term_Query() is your best bet:
$term_args = array(
'taxonomy' => 'category',
'name' => array( 'accessibility','wcag', 'abc' )
'hide_empty' => false,
'fields' => 'all',
'count' => true,
);
$term_query = new WP_Term_Query($term_args);
foreach($term_query->terms as $term){
echo '<pre>';
print_r($term); // You'll see the term object here, which is what I think you are after
echo '</pre>';
}
本文标签: theme developmentHow to get category lists by name or slug
版权声明:本文标题:theme development - How to get category lists by name or slug 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745371087a2655733.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论