get_the_category_list
should do the trick:
get_the_category_list( ', ', '', $prev_post->ID )
Question
I have a Next Post link at the bottom of my Wordpress article.
I am using get_adjacent_post to display the post title. I would also like to show the attached categories with my this post.
I can't find how I should write this. My attempt is:
<?php
$prev_post = get_adjacent_post(false, '', true);
if(!empty($prev_post)) {
echo '<div class="next"><a href="' . get_permalink($prev_post->ID) . '" title="' . $prev_post->post_title . '"><span class="link">Next article →</span><br/>' . $prev_post->post_title . '<br/><span class="grey">Filed under: ' . $prev_post->post_category . '</span></a></div>'; }?>
$prev_post->post_category doesn't work. Does anyone know the correct syntax?
Thanks!
Solution
get_the_category_list
should do the trick:
get_the_category_list( ', ', '', $prev_post->ID )