I have created a 404 error template. whose main portion looks like this →

    <div class="main col <?php post_class(); ?>">
        <h2>Sorry Boss! This Page doesn't exist.</h2>            

And the above works quite well. see here a page that doesn't exist.

Apart from this error notice I was trying to show top 10 recent posts. so I was trying use the WP Loop →

        <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); >
        <?php get_template_part('content','home'); ?>
        <?php endwhile; ?>
        <?php endif; ?>

perhaps there should be some other way to achieve this, but I want that this template should be used →

<?php get_template_part('content','home'); ?>

so that I can get 10 posts.

1 Answer 1


The Loop just outputs what is contained in the Main Query, it doesn't fetch any posts on its own. The Main Query is empty on a 404, so there's nothing for The Loop to output.

If you want additional content, you have to query for it yourself:

$query = new WP_Query( array('posts_per_page' => 10) );
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
endwhile; endif;
  • Thanks, sir. I am a beginner, and this was enlightening for me.
    – WordCent
    Jun 7, 2017 at 17:31

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.