for example, if main category slug is cars;
sub-category slug is: Ford; how to get the permalink of Ford, including its parent categories' slug?
( get_category_link() returns mysite.com/?cat=19 type of link, but i want mysite.com/cars/ford )


my solution:

$cats = get_category ($catid);
if ($cats) 
    {$category_link = $cats->slug;
        if ( $parent = $cats->parent )
            $category_link = get_category_parents($parent, false, '/', true) . $category_link;
| improve this answer | |
  • 2
    Please accept your own answer. This question keeps on rotating as unresolved. – Pieter Goosen Dec 28 '15 at 5:59
  • Also, please post a proper solution with proper explanation with what your code does – Pieter Goosen Dec 28 '15 at 7:12

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.