1

I have CPT 'movie', with the following taxonomies: genre, director, and actor.

The code used to register these is this: http://pastebin.com/yJ9XHCDk

I have an archive movie page working using the following code in archie-movie.php:

<?php get_header(); ?>

    <div id="middle" class="clearfix">          
    <div id="inner">                     
    <div id="content" class="<?php echo $bw; ?>">

        <?php get_template_part( 'part-genrenav'); ?>

        <div id="pageHead">
            <?php global $post; if(is_archive() && have_posts()) :
                    if ( is_post_type_archive() ) { ?>
                        <h1><?php post_type_archive_title(); ?></h1>
                        <?php } ?>
            <?php endif; ?>
        </div>

        <div class="posts clearfix">
            <?php get_template_part( 'part-pagination'); ?>
        <?php while (have_posts()) : the_post(); ?>             
            <?php get_template_part( 'part-movie'); ?>              
        <?php endwhile; ?>          
        <?php get_template_part( 'part-pagination'); ?>
        </div>                  
    </div>      
    </div>          
    </div>

<?php get_footer(); ?>

Taxonomy.php

I've created a taxonomy.php (and a taxonomy-genre.php and so on). Taxonomy.php is being called correctly here, but the loop in that template returns nothing. I've been back and forth through dozens of articles, but can't seem to figure it out.

Currently, my taxonomy.php file is made up of this, as you can see it isn't much different than they archive-movie.php file above. I just can't figure out why it doesn't work:

<?php get_header(); ?>

    <div id="middle" class="clearfix">          
    <div id="inner">                     
    <div id="content">

        <div id="pageHead"><h1>Taxonomy Archive</h1></div>

        <div class="posts clearfix">
            <?php get_template_part( 'part-pagination'); ?>
        <?php while (have_posts()) : the_post(); ?>             
            <?php get_template_part( 'part-movie'); ?>              
        <?php endwhile; ?>          
        <?php get_template_part( 'part-pagination'); ?>
        </div>  

    </div>      
    </div>          
    </div>

<?php get_footer(); ?>
  • Obvious questions: have you assigned taxonomies to your movie posts? and does the part-movie.php template exist? – helgatheviking Jun 17 '14 at 14:01
  • Yes, you can see in the linked pastebin that the taxonomies have been associated with the post type move, both from within the tax registration and within the movie registration. part-movie.php exists and is working correctly when called by archive.movie.php – Prometheus Fire Jun 17 '14 at 14:30
  • I didn't mean did you register the taxonomy correctly. I meant, do you have any movies in the taxonomy in question? (Assigned via the taxonomy metabox when editing the movie post) – helgatheviking Jun 17 '14 at 14:36
  • Yes, here is a movie page to see how I've got them organized by taxonomies: dev.prometheusfire.me/schmoovies-development/movie/… – Prometheus Fire Jun 17 '14 at 14:44
4

I think you may need to filter the query for that taxonomy so it displays your movie custom post type.

Try adding this to your theme's functions.php file:

function custom_post_archive($query) {
    if (!is_admin() && is_tax('genre') && $query->is_tax)
        $query->set( 'post_type', array('movie', 'nav_menu_item', 'post') );
    remove_action( 'pre_get_posts', 'custom_post_archive' );
}
add_action('pre_get_posts', 'custom_post_archive');

You'll need to add to that function for all your various taxonomies but this is a good way to test it's the issue/solution first.

See this post - and read through all the comments - for a bunch of other ways to filter the query and add conditionals.

  • Thank you! You nailed it. I can't vote this up because I'm still a new user, but this passed the information about the post type correctly and now the archives are working. Thank you! – Prometheus Fire Jun 17 '14 at 15:16
  • I'm surprised this is needed since the taxonomy was registered for this post type, but good solve! +1 from me. I would suggest moving it out of the functions.php and into a site-specific plugin in the mu-plugins folder though. This is functionality and not display, so you don't want to lock it into a theme. – helgatheviking Jun 17 '14 at 15:26
  • I found that this got me out of trouble. As Helga mentioned put it in the plugin that you're making the custom taxonomy within. Also this should be the accepted answer – AceWebDesign Nov 14 '16 at 22:23
0

I'm going to start by switching your loop to check if it has any posts and if not returning a notice that nothing was found. At least that will help narrow the problem down... as well as not return a blank page.

<?php get_header(); ?>

    <div id="middle" class="clearfix">          
    <div id="inner">                     
    <div id="content">

        <div id="pageHead"><h1>Taxonomy Archive</h1></div>

        <div class="posts clearfix">
            <?php get_template_part( 'part-pagination'); ?>

            <?php if( have_posts() ) : ?>

            <?php while (have_posts()) : the_post(); ?>             
                <?php get_template_part( 'part-movie'); ?>              
            <?php endwhile; ?>    

            <?php else: ?>

                <?php _e ( "Sorry, no movies were found", "your-theme" ); ?>

            <?php endif; ?>

            <?php get_template_part( 'part-pagination'); ?>
        </div>  

    </div>      
    </div>          
    </div>

<?php get_footer(); ?>
  • Thank, no luck though. dev.prometheusfire.me/schmoovies-development/genre/comedy I tried iterations of that so I could keep track things, but removed it to streamline the loop. Still not returning anything. I'm using the Helpful Information plugin, and it is showing the correct template, but Post Type for the page is blank. Do I have to identify the post type in the template somehow? – Prometheus Fire Jun 17 '14 at 14:42
  • When I inspect the page the Helpful Information plugin, the part-movie.php file isn't even being called. So its not failing inside that file, it is failing when the loop begins and finds no posts. – Prometheus Fire Jun 17 '14 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.