WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to obtain the data from a certain page outside the regular flow, more efficiently than via get_post($id)? I know that I can get for example the title with

$post = get_post($id);
$title = $post->post_title;

But I prefer to use the loop, rather than picking every single page element in the way I described above. So what I want, is to read the entire page data, and then perform a 'regular loop', using the_title(), the_content(), the_post_thumbnail() etc.

The reason why I ask this is because I'm busy creating a '404 solution' for my theme, where one is able to create and edit a custom 404 page in the WordPress backend.

share|improve this question
up vote 0 down vote accepted

You need to use setup_postdata().

$post = get_post( $id );
setup_postdata( $post );

if(! empty( $post ) ){
  echo '<br>';
else {
  echo "No page found matching ID $id";
share|improve this answer
Thanks that's it! – Toine Apr 10 '14 at 7:20
You should accept the answer if it fixed your problem. – RRikesh Apr 10 '14 at 7:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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