0

I've a list of url's and I want to get the categories of each one. Whats the best way to achieve this?

Thanks. Diego

0
$category_slug_array = array('slug_1', 'slug_2', 'slug_2'); //array of category slugs

foreach($category_slug_array as $category_slug){
   $my_categories[] = get_term_by( 'slug', $category_slug, 'category'); //getting category object by slug
}

print_r($my_categories); //printing array of categories 
  • Could you please edit your answer and add in an explanation on what this piece of code does, where to add it, and how it solves the original issue? – Howdy_McGee Feb 1 '18 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.