[wp-trac] [WordPress Trac] #40253: the_content problem

WordPress Trac noreply at wordpress.org
Fri Mar 24 19:46:32 UTC 2017


#40253: the_content problem
-------------------------------+-----------------------------
 Reporter:  tazotodua          |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 Hi.
 I think it is quite essential problem.

 lets say I want to check, if post's custom field "smth" is 1, then I want
 to set content to "Hello World".

 add_filter('the_content', function($content){
     global $post;
     if(get_post_meta($post->ID, 'smth', true ) == 1 ){
       $content = "Hello World";
     }
     return $content;
 });


 but problem raises, when we access single post, which has set it's custom
 field to `smth` to 1, but also,  `the_content` is also changed to `Hello
 World` everywhere else (in sidebars, recent posts and etc... everywhere),
 because in `the_content` we make comparison for the GLOBAL POST's data.  I
 think there should be some kind of additional parameter with `the_content`
 filter, which will indicate if it is the main content of single page.




 the same problem (but oppositely) arises, when we want to filter
 `the_content` in all areas, but not for the main post-s content..

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


More information about the wp-trac mailing list