I'm trying to get associated array out of taxonomy slug and taxonomy name. I have this
foreach (get_terms('taxonomy') as $tax_term) {
$taxonomy_slug = $tax_term->slug;
$taxonomy_name = $tax_term->name;
}
The issue is, that these are just strings glued together, I don't know how to separate them :\ When I print_r
them out I get:
term1term2term3term4
...
What I need is a way to separate those, and then create array that will look like this:
Array(
['term_1'] => Term 1
['term_2'] => Term 2
...
)
Is this possible?
As per your inputs in comments I have tried to find out the solution. Hope this will helps you.
$terms = array();
foreach (get_terms('taxonomy') as $tax_term) {
$taxonomy_slug = $tax_term->slug;
$taxonomy_name = $tax_term->name;
$exploded = explode($taxonomy_name,$taxonomy_slug);
foreach ($exploded as $termValue) {
if (!empty($termValue)) {
$terms[$taxonomy_name."_".$termValue] = ucfirst($taxonomy_name)." ".$termValue;
}
}
}
echo "<pre>"; print_r($terms);