theme development - How to get category lists by name or slug

Currently I am able to get all categories but I want only few categories to display based on name or slug for example. $

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
Add a comment  | 

1 Answer 1

Reset to default 1

If 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>';
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745371088a4624797.html

相关推荐

  • theme development - How to get category lists by name or slug

    Currently I am able to get all categories but I want only few categories to display based on name or slug for example. $

    23小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信