I have set up a category.php
according to this wordpress hierarchy diagram.
When I am on the page http://example.com/category/my-category I want to display all posts that are under my-category
using the loop:
<?php if (have_posts()): while (have_posts()): the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php endwhile; endif; ?>
WordPress is not showing the posts.
I will also add that this is a custom post type, but that shouldn’t matter or should it?
I can use get_posts()
but then what is the point of having a category.php
?
How do I show the posts in the current category using the_loop
?
In fact, this is your problem.
By default, the Category Archive Index will only query posts from the
post
post-type. You need to tell WordPress to do otherwise, by adding your custom post type to the query viapre_get_posts
: