Skip to content

Instantly share code, notes, and snippets.

@michael-milette
Created September 26, 2017 20:21
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 michael-milette/d128fda7ba6f65241ca77212c85e3a5f to your computer and use it in GitHub Desktop.
Save michael-milette/d128fda7ba6f65241ca77212c85e3a5f to your computer and use it in GitHub Desktop.
Get a list of all WordPress categories as an array
/*
* Get a list of all categories in WordPress and return them as an array.
*/
function getCategoriesArray() {
// Retrieve object containing all of the categories.
$cats = get_categories();
// Convert the object into a simple array containing a list of categories.
$categories[] = '';
foreach($cats as $category) {
$categories[] = __( $category->cat_name, 'hs_textdomain' );
}
// Return the array.
return $categories;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment