Skip to content

Instantly share code, notes, and snippets.

@dompl
Created September 9, 2022 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dompl/b1f9f6d0846b277996880c5d954e5a9c to your computer and use it in GitHub Desktop.
Save dompl/b1f9f6d0846b277996880c5d954e5a9c to your computer and use it in GitHub Desktop.
Get WordPress categories list with args
$categories = get_categories( [
'taxonomy' => 'category',
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => 0,
'pad_counts' => false,
// full list of params: http://wp-kama.com/function/get_terms
] );
if( $categories ){
foreach( $categories as $cat ){
// $cat->term_id
// $cat->name (Category 1)
// $cat->slug (category-1)
// $cat->term_group (0)
// $cat->term_taxonomy_id (4)
// $cat->taxonomy (category)
// $cat->description (text)
// $cat->parent (0)
// $cat->count (14)
// And aliases:
// $cat->object_id (2743)
// $cat->cat_ID (4)
// $cat->category_count (14)
// $cat->category_description (text)
// $cat->cat_name (Category 1)
// $cat->category_nicename (category-1)
// $cat->category_parent (0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment