Getting the category slug
-
Hello,
I hope I make sense with this question… As far as I can tell getting the slug from a category should be easy and outside of the loop I can get the category slug or name only once in a foreach loop using variable assigned with wp_get_recent_posts(). I’m making a featured posts section with the five most recent posts and I’m trying to get the slug from these first five posts because I’m trying to make an array out of the three categories I have with a number value of how many posts belong to each category getting pulled, that way the rest of the front page won’t display duplicate posts if it’s not a part of the first five. My main problem is since I can only seem to get the slug once for only one of the categories I can’t populate my array with these values correctly. So what I’ve been using, unsuccessfully, in my foreach loop is:$cat = get_the_category($main['ID']);//$main['ID'] being the post it's pulling $parent = get_category($cat->category_parent); $parentName = $parent->cat_name;For testing reasons I only tried doing a print_r($array) which won’t print anything on the screen and var_dump($array) which prints NULL five times. So, the problem is nothing seems to be assigning to it, but I can’t seem to bridge that gap with a WP function. I hope I make sense with that. Any help is greatly appreciated.
Thanks!
The topic ‘Getting the category slug’ is closed to new replies.