• Hi there,

    I am developing an API that its input is post ID. In the API, I want to get the post content. However, if the content has line-break (<!–nextpage–>). How can I get the content of each page?

    After researching, I found a function generate_postdata that will return the pages. However, it only supports in 5.2.0. Then I used another function setup_postdata.

    My codebase:

    
    if ( function_exists( 'generate_postdata' ) ) {
       $postdata = generate_postdata( $post );
       $pages    = $postdata['pages'];
    } else {
       setup_postdata( $post );
       global $pages;
    }
    

    Is it the correct way or is there any side effect?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    That’s fine, but you could simply use setup_postdata() in all cases. Aside from assigning some globals, it now calls generate_postdata() to do most of its work anyway. With 5.2, a good part of setup_postdata() code was basically split out into generate_postdata() as a sub-routine.

    Thread Starter gaupoit

    (@gaupoit)

    Thanks for your response. Appreciate it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Line break page content’ is closed to new replies.