Skip to content

Instantly share code, notes, and snippets.

@mdjwel
Created May 22, 2018 08:51
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 mdjwel/5016a5ab96890bc94f3af42eac054676 to your computer and use it in GitHub Desktop.
Save mdjwel/5016a5ab96890bc94f3af42eac054676 to your computer and use it in GitHub Desktop.
Get associative array (cat_slug => cat_name) in WordPress
<?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