I already posted the same exact thing on stackoverflow without any comments or answer, i hope to get something going here:
I'm trying to change the post content of a page by hooking into "the_post" action, but the problem is that wathever i modify in there doesn't really get applied correctly.
The problem seems to come from the fact that "query->setup_postdata" creates a $pages variable and sets the content into it before calling the "the_post" hoook. So whatever changes i do to the $post object doesn't reflect in the page.
Further down the road, it seems that the "get_the_content" function which calls the "the_content" filter uses the content from $pages instead of the $post->post_content. Thus if i change the content of the post, it will not output it correctly because wordpress bases itself off something else to print out the content.
Now if i hook unto "the_content" filter and replace the text using a simple hook mechanism such as:
public function wordpress_hooks_the_title($title){
if(get_the_ID() == 4){ return 'test title'; }
return $title;
}
public function wordpress_hooks_the_content($content){
if(get_the_ID() == 4){ return 'test content'; }
return $content;
}
It works fine for the content, but the title overrides many other titles in the page such as in the menu, even if i call "get_the_ID()" which is fine because the current $post is ok...
So i'm stuck trying to find the right way and not a half and half way. I'd like to use "the_post" only or "the_content/the_title" only but only half of them work fine in each context.
What would be the right approach?
Thanks
