You can use get_terms()
to retrieve the custom taxonomy terms and then build up a custom array to match the structure you want.
Try this:
//Get the custom taxonomy terms
$taxonomies = array(
'name' => 'your_custom_taxonomy' //Edit to match your needs
);
$taxonomy_terms = get_terms( $taxonomies );
//This array will store the results
$taxonomy_array = array();
//Parse the terms
foreach ( $taxonomy_terms as $taxonomy_term ) :
//Get the taxonomy term name
$taxonomy_term_name = $taxonomy_term->name;
//Get the taxonomy term slug
$taxonomy_term_slug = $taxonomy_term->slug;
//Push the custom array
$taxonomy_array[ $taxonomy_term_name ] = $taxonomy_term_slug;
endforeach;
The data will be stored in $taxonomy_array
following the format you provided. You can pass additional arguments to get_terms()
, such as the order.