asked 4 years ago

I want to show a list of the latest posts with the category displayed for each post.
I used a WP_Query to show the posts as I would usually do which is working fine. But the category is not displaying.
I use the_category(); to normally display the category, but this shows no result so I also tried:
print_r( get_the_category($post->ID) );
both of which have no results.
I checked and the posts i’m querying 100% have the categories selected in the wp-admin > edit post.
so in php can you tell me how to get the post category please?
Here’s a grab of my code. with $categoryArgs included it correctly shows just the posts in the ‘tech’ category.

1 Answers
answered 4 years ago

You can replace the_ccategory() with the following code: 

echo get_the_term_list( get_the_ID(), 'dwqa-question_category', '<span class="dwqa-question-category"><span class="dwqa-sep">' . __( '&nbsp;&bull;&nbsp;', 'dwqa' ) . '</span>', ', ', '</span>' );
replied 4 years ago

AMAZING!!! – thanks soo much! – I think you have used this snippet before 🙂

Thanks for understanding my issue and for your very exact and efficient response!

Dominic Staff
replied 4 years ago

If you have any issue, you can let me know. We will check and help you resolve it.

Powered by DW Question & Answer Pro