Created
September 9, 2022 06:53
-
-
Save dompl/b1f9f6d0846b277996880c5d954e5a9c to your computer and use it in GitHub Desktop.
Get WordPress categories list with args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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