• Hi everybody,

    I’ve created a custom post type ‘photos’ with a custom taxonomy ‘photo-gallery’.
    Now I’m trying to create a template file taxonomy-photo-gallery.php that returns all entries in this category/term /photo-gallery/slug-of-term/

    Somehow I can’t get it to work properly, when using the default
    <?php if ( have_posts() ): ?>
    <?php while ( have_posts() ) : the_post(); ?>
    I always get the “no posts to display” message instead of the posts of the term.

    And when I try to find a solution I only find more complex stuff which I don’t know how to modify.

    For example, this code returns the term name and lists all posts within that term, but does so for all terms and not just the one term that is defined in the URL. https://pastebin.com/d12EBFDS

    I thought getting rid of the ‘foreach’ part and finding a way to get_term() the slug would be the solution, but I can’t get it to work. And I also suspect that there is a much easier solution to this. And I’m looking for a solution that does not require to define the name of the term manually.

    Does anybody have an idea on how to loop through the entries of the term in a taxonomy-photo-gallery.php? Any help would be greatly appreciated.

    Thanks a lot.

  • The topic ‘WP_Query for custom post type taxonomy terms’ is closed to new replies.