Alex Barber | Digital Artist

time to push the pixels

WordPress get category slug from its name

http://wptricks.net/how-to-detect-category-id-using-the-category-slug-in-wordpress/

Used this to get category slug from its name

$category = get_the_category();
$catname = $category[0]->cat_name;

$catslug = get_term_by(‘name’,$catname,’category’);

echo $catslug->slug;

Next Post

Previous Post

© 2022 Alex Barber | Digital Artist