Make WordPress Core

Opened 16 years ago

Closed 11 years ago

#14958 closed enhancement (wontfix)

Add a "get_post" filter to get_post()

Reported by: mikeschinkel Owned by:
Priority: normal Milestone:
Component: Query Version:
Severity: normal Keywords:
Cc: Focuses:

Description

I'm finding a need for a plugin of mine to generically annotate a post with additional information when loaded via get_post(). It would be nice if there were a filter just before the end where the post is still in object form.

Attachments (1)

post.php.diff (387 bytes ) - added by davidmosterd 14 years ago.
Adds filter 'get_post' to the get_post() function.

Download all attachments as: .zip

Change History (11)

#1 @mikeschinkel
16 years ago

  • Cc mikeschinkel@… added

#2 follow-up: @Denis-de-Bernardy
16 years ago

You can use the_posts and the_post in the meanwhile.

#3 in reply to: ↑ 2 @mikeschinkel
16 years ago

  • Cc mikeschinkel@… removed

Replying to Denis-de-Bernardy:

You can use the_posts and the_post in the meanwhile.

Thanks. OTOH, you are aware that 'the_post' is called by setup_postdata($post) which is not relevant in the use-case that caused me to need this. FWIW, I was wanted to add in the addition values so that when so that when a wp_insert_post_data() was later called the post would have everything needed to save correctly. So I was not needed anything related to the loop here.

-Mike

#4 @nacin
16 years ago

  • Keywords needs-patch 2nd-opinion added
  • Milestone Awaiting ReviewFuture Release

#5 @davidmosterd
14 years ago

+1

As an alternative use WP_Query instead of the direct select query in WP_Post?
I suppose it might be a performance issue, I don't know. But it would allow the use the filters and actions from WP_Query.

@davidmosterd
14 years ago

Adds filter 'get_post' to the get_post() function.

#6 @davidmosterd
14 years ago

  • Keywords has-patch dev-feedback added; needs-patch removed

I added a patch. How do you feel on the location and name of the filter?

#7 @davidmosterd
14 years ago

Maybe add the parameters of get_post to the filter might not be a bad idea? It might matter what was supplied to get_post() for the ones using this filter.

#8 follow-up: @wonderboymusic
13 years ago

  • Keywords close added; 2nd-opinion dev-feedback removed

get_post() returns a WP_Post instance - you can decorate that.

$post = get_post( $id );
$post->extra = 'sauce';

#9 in reply to: ↑ 8 @MikeSchinkel
13 years ago

Replying to wonderboymusic:

get_post() returns a WP_Post instance - you can decorate that.

$post = get_post( $id );
$post->extra = 'sauce';

Unfortunately that solution does not address the use-case for which I posted this ticket. Further, it being a WP_Post isn't relevant to the proposed solution because you could have done exactly the same before when it was an stdClass object.

The goal of the ticket was to gain the ability to ensure that all posts that were retrieved for a selected post type had been decorated with other items, i.e. custom fields, child posts, etc. It could also be a method for instrumentation or anything else you'd want to do to ensure that all posts objects created WordPress' code, by other plugin's code or by themes have the properties desired.

However, since the 3 years that have passed as this ticket languished the inclusion of WP_Post actually provides a better location for the hook to address the desired use-case, i.e. in the constructor of WP_Post. Given that it does makes sense to close this ticket but not for the reasons you mentioned but because a new ticket is more relevant; an 'instantiated_post' hook.

#10 @chriscct7
11 years ago

  • Keywords has-patch close removed
  • Milestone Future Release
  • Resolutionwontfix
  • Status newclosed

There has been no interest or activity in two years. Closing as wontfix.

Note: See TracTickets for help on using tickets.