Created
May 22, 2018 08:51
-
-
Save mdjwel/5016a5ab96890bc94f3af42eac054676 to your computer and use it in GitHub Desktop.
Get associative array (cat_slug => cat_name) in WordPress
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
<?php | |
// Category array | |
function chaoz_cat_array($term='portfolio_cat') { | |
$cats = get_terms(array( | |
'taxonomy' => $term, | |
'hide_empty' => true | |
)); | |
$cat_array = array(); | |
$cat_array['all'] = esc_html__('All', 'gullu'); | |
foreach ($cats as $cat) { | |
$cat_array[$cat->slug] = $cat->name; | |
} | |
return $cat_array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment