If you have your custom post type rewrite rules set up properly, you shouldn’t need to create a new WP_Query
in your template file. Comment out the new WP_Query
line or rename your portfolio-single.php
so WP pulls from the default single.php
and see if it pulls the proper post. You can also call echo $post->ID
inside the loop to see what post WP is pulling in each iteration of the loop.
If that doesn’t fix your issue, you can use this function to verify what template files are being used.
Add this to your functions.php
:
function _dump_files()
{
add_action( 'all', create_function( '', "echo '<pre>'; print_r( get_included_files() ); echo '</pre>'; return;" ) );
}
Then change the end of your footer.php
to be this:
<?php wp_footer(); ?>
<?php
if (is_user_logged_in()) {
_dump_files() ;
}
?>
</body>
</html>
This way you can make sure WP is using the right files – you may find it’s not including your custom template file (usually because the name doesn’t match the internal name from the CPT when originally set up). Also, keep in mind CPT internal names should be all lowercase, using alpha characters only to avoid weird behaviors.