0

I have a custom page template where I also want to display a list of posts.

Normally in a page you can just use the following code to display content

<?php while(have_posts()): the_post(); ?>
    <?php the_content(); ?>
<?php endwhile; ?>

But what if before I display the page content, I have a custom query to display a list of posts? How can I after displaying those posts, go back to the original query to display page information?

1

1 Answer 1

1

After your custom query, call wp_reset_postdata() function to get back default wordpress loop.

<?php wp_reset_postdata(); ?>

For more info and example check at http://codex.wordpress.org/Function_Reference/wp_reset_postdata

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I overlooked that section in the documentation.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.