#44788 closed enhancement (invalid)
the_content() strange behavior - we can't change global "post_content" from "$post->post_content"
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.9.8 |
| Component: | Posts, Post Types | Keywords: | |
| Focuses: | Cc: |
Description
Look at this code, is it normal?
<?php global $post; echo $post->post_content; //> Some text $post->post_content = 'New text'; the_content(); //> Some text
Change History (5)
#2
@
7 years ago
Just to elaborate @windyjonas reply a bit:
the_content() calls the following function in wp-includes/post-template.php
function the_content( ... ) {
$content = get_the_content( ... ) // invokes get_the_content()
...
}
function get_the_content( ... ) {
...
$post = get_post();
}
#3
@
7 years ago
- Summary changed from the_content() strange behavior - we cant change golobal "post_content" from "$post->post_content" to the_content() strange behavior - we can't change global "post_content" from "$post->post_content"
#4
@
7 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
- Type changed from feature request to enhancement
To clarify a bit more, setting $post->post_content does affect the $post global, however that's not the value used in get_the_content(), at least not directly.
The function takes $content from the $pages global, which is set up in WP_Query::setup_postdata earlier.
It's not quite clear when exactly your snippet runs, but it should work if you add setup_postdata( $post ) after changing $post->post_content.
Note: See
TracTickets for help on using
tickets.
Yes, the_content starts with a