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

2

1 Answer 1

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 
1
  • 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, 2018 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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