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
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI'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
$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