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.
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>' );
Please login or Register to submit your answer