How to fix get_the_category function returning incorrect slug?


So, I’m having an issue where using the get_the_category function is returning an incorrect slug. My code snippet is as so:

 <?php $category_detail=get_the_category($post->ID);
        foreach($category_detail as $cd){?>
        <li class="list-inline-item"><a href="<?php echo $cd->slug ?>"><?php echo $cd->cat_name; ?></a> 
   </li><?php } 

The issue is that the category slug doesn’t reflect my site’s permalink settings, and returns: "" and not "". I am not sure why the category permalink is being truncated, as the category pages work correctly, but this function is outputting them incorrectly, The slug in question here is for regular posts.

nizz0k 2 months 0 Answers 10 views 0

Leave an answer