[wp-trac] [WordPress Trac] #12955: Add get_post filter

WordPress Trac noreply at wordpress.org
Mon Sep 29 12:35:03 UTC 2014


#12955: Add get_post filter
-------------------------------+-----------------------------
 Reporter:  JohnLamansky       |       Owner:
     Type:  feature request    |      Status:  new
 Priority:  normal             |   Milestone:  Future Release
Component:  Posts, Post Types  |     Version:
 Severity:  normal             |  Resolution:
 Keywords:  has-patch filter   |     Focuses:
-------------------------------+-----------------------------

Comment (by nikolov.tmw):

 I second the idea for a filter on `get_post()`, but I just ran into a
 possible side effect of the suggested patch.

 Having the following super-simple code:
 {{{
 function my_post_filter( $post ) {
         $post->post_title .= ' | Filters are awesome';

         return $post;
 }
 add_filter( 'get_post', 'my_post_filter', 10 );
 }}}

 Results in the main post being displayed having it's title become
 something like this: "Hello world! | Filters are awesome | Filters are
 awesome | ...".
 Now my question is the following - should we leave it up to the developers
 to make sure they're not filtering the same object multiple times, or
 should we come-up with an idea of how to avoid having to do that in the
 first place?

 WP_Post::filter() seemed like a good place, but it never seems to run
 under normal circumstances, since the passed `$filter` is always the same
 as `$this->filter`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/12955#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list