Created
September 26, 2017 20:21
-
-
Save michael-milette/d128fda7ba6f65241ca77212c85e3a5f to your computer and use it in GitHub Desktop.
Get a list of all WordPress categories as an array
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
/* | |
* 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