1

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.

1 Answer 1

0

You need to use setup_postdata().

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

if(! empty( $post ) ){
  the_title(); 
  echo '<br>';
  the_content();
}
else {
  echo "No page found matching ID $id";
}
0

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.