#29732 closed defect (bug) (invalid)
post_template.php get_the_content() incorrect work when run without get_header?
Reported by: | Skynin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.1 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
Hi!
I use AJAX in my theme, and use routing WP
The simple example:
file: single-mytypepost.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():
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)
Change History (6)
#4
in reply to:
↑ 1
;
follow-up:
↓ 5
@
10 years ago
Replying to comment:1 SergeyBiryukov:
get_the_content()
should only be used inside the loop. Looks like you're trying to call it separately.
Yes, I use outside the loop for a selected page. Global variable $post is initialized in this case, therefore i assumed that everything will work.
Thank you for the answer.
This ticket(#29732) can be removed.
#5
in reply to:
↑ 4
;
follow-up:
↓ 6
@
10 years ago
Replying to Skynin:
Global variable $post is initialized in this case, therefore i assumed that everything will work.
setup_postdata() would probably help.
#6
in reply to:
↑ 5
@
10 years ago
Replying to SergeyBiryukov:
setup_postdata() would probably help.
yes, it is! I was lazy. i'm sorry.
very thanx
get_the_content()
should only be used inside the loop. Looks like you're trying to call it separately.