I have been unable to get my single-portfolio.php template to behave properly.

So I have a custom post type called portfolio. I am displaying all of those posts in the front-page.php and it works perfectly fine. Here is the loop for the front-page.php:


For the life of my however, I cannot get the right post to show up in my single-portfolio.php template.

Basically, if I go to one of my posts (so for example, lets say http://example.com/portfolio/test-post/) I end up with a single post page that displays the wrong post (so instead of "test-post" I get "wrong-post"). No matter what post I open up, it will be the exact same post that is displayed ("wrong-post"). If I set the posts_per_page to infinite, it will show me all of the posts.

I have tried many different Loops. I have tried the exact same loop as shown above, as well as the default custom post type loop found in the Wordpress Codex:

$args = array( 'post_type' => 'product', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    echo '<div class="entry-content">';
    echo '</div>';

Any suggestions on how to solve this?


  • Can you add your single-portfolio.php code?
    – fdsa
    Jul 16, 2012 at 21:52
  • I updated my post above to include the Loop I was referencing. I have tried some variations of the Loop I linked to with pastie as well as the default Wordpress loop, and no luck. Also, just to be clear, I have disabled all plugins to troubleshoot.
    – beefchimi
    Jul 16, 2012 at 22:05

1 Answer 1


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(); ?>
    if (is_user_logged_in()) {
        _dump_files() ;

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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