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:
the_category($post->ID);
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.
https://www.evernote.com/l/ARcAlAjujstEka1S_2kxSWcd9-ibJq66gWI
Thanks
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">' . __( ' • ', 'dwqa' ) . '</span>', ', ', '</span>' );
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!
If you have any issue, you can let me know. We will check and help you resolve it.
Please login or Register to submit your answer