[wp-trac] [WordPress Trac] #29732: post_template.php get_the_content() incorrect work when run without get_header?

WordPress Trac noreply at wordpress.org
Tue Sep 23 10:17:42 UTC 2014


#29732: post_template.php get_the_content() incorrect work when run without
get_header?
--------------------------+-----------------------------
 Reporter:  Skynin        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Post Formats  |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hi!

 I use AJAX in my theme, and use routing WP
 The simple example:
 file: single-mytypepost.php
 {{{
 #!php
         if ($_GET['ajax']) {
                 echo get_the_content(); // 1
                 die();
         }
         else {
                 get_header();
                 echo get_the_content();
                 get_footer();
         }
 }}}
 don't work line 1, because
 trace body get_the_content() - $pages is null!

 My fix is in get_the_content():
 {{{
 #!php
     if (empty($pages)) { // fix, check global var $pages
         $content = $post->post_content;
     }
     else {
         if ( $page > count( $pages ) ) // if the requested page doesn't
 exist
             $page = count( $pages ); // give them the highest numbered
 page that DOES exist

         $content = $pages[$page - 1];
     }
 }}}

 Best regards,
 Sergey (Skynin)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29732>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list