WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

Let's say I have a post that has been paginated by adding the

 <!-- nextpage --> 

code provided by wordpress for this purpose. How can I then query a specific page from inside of that post. Say for instance I only want to query the contents of page 2 and there are 10 posts. Is there a way to do it?

share|improve this question
up vote 1 down vote accepted

WordPress uses the PHP explode function to split the content into a array of 'pages'. Happens in the setup_postdata function with this code:

$pages = explode('', $content);


So you could do something like :

function wpse_103026( $content, $pagenum ) {
  if ( strpos( $content, '<!--nextpage-->' ) ) {
    $pages = explode('<!--nextpage-->', $content); 
    return isset ( $pages[$pagenum-1] ) ? trim( $pages[$pagenum-1] ) : $content;
    } else {
    return false;

And then you can retrieve content of page 4 with :

echo apply_filters( 'the_content', wpse_103026( $post->post_content, 4 ) );
share|improve this answer
Fantastic! Thanks for the complete solution. – MikeGWP Jun 14 '13 at 23:27

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.