get_the_content()
doesn’t actually return the post_content
property from the global $post
object. Instead it returns the first page of the global variable $pages
, which is set before the_post
hook is fired. See L287 of wp-includes/post-template.
To reset the $pages
global, you can use the setup_postdata()
method from the WP_Query
object passed from the the_post
hook.
add_action( 'the_post', 'wpse_the_post', 10, 2 );
function wpse_the_post( $post, $query ) {
$post->post_title="Foo";
$post->post_content="Yolo";
//* To prevent infinite loop
remove_action( 'the_post', 'wpse_the_post' );
$query->setup_postdata( $post );
add_action( 'the_post', 'wpse_the_post', 10, 2 );
}
This is kind of backwards since you’re then setting up the post data twice. But if you’re intent on using the_post
hook…
I’d use two different filters instead (the_title
and the_content
).