Make WordPress Core

Opened 16 years ago

Closed 15 years ago

Last modified 3 years ago

#6284 closed enhancement (fixed)

add a the_post hook

Reported by: denis-de-bernardy's profile Denis-de-Bernardy Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.5
Component: Optimization Keywords: has-patch tested commit
Focuses: Cc:


Could we add a the_post hook, fired when the_post() gets called?

Its absence led me to this bug while investigating a workaround:

Thanks -- D

Attachments (1)

6284.diff (414 bytes) - added by Denis-de-Bernardy 15 years ago.

Download all attachments as: .zip

Change History (12)

#1 @lloydbudd
16 years ago

  • Milestone changed from 2.5 to 2.6

#2 @pishmishy
16 years ago

It's not clear from your other ticket what you're trying to achieve and how it would be helped by this hook. Please could you supply us with further information.

#3 @Denis-de-Bernardy
15 years ago

  • Keywords has-patch tested added
  • Milestone changed from 2.9 to 2.8

The purpose was (and still is) to apply filters conditionally on the post.

As a temporary workaround, I end up doing something like this:

on loop start, look at first post. if condition is met, remove all filters on the_content, except the one that checks the next post.

on the_content, look at next post, if condition is met, remove all filters on the_content, except the one that checks the next post, else restore the filters on the_content.

on loop end, restore all filters on the_content.

it's actually not all the filters, but much about. my purpose in doing so is to conditionally disable wpautop, texturize, etc. based on a postmeta's value.

#4 @azaozz
15 years ago

Would a hook be better there or in setup_postdata()?

#5 @Denis-de-Bernardy
15 years ago

Worth a discussion.

Personally, I use setup_postdata() on singular pages to set a few <meta> tags in my page's header using WP's built-in functions. I might be alone doing this, and would of course fix this accordingly. :-)

Leaving it up to you to decide, as long as the hook is around.

#6 @azaozz
15 years ago

Couldn't that be done by using the_content as an action with higher priority? Something like:

add_filter( 'the_content', 'my_function', 1 );
function my_function( $content ) {
    // add or remove filters for this post...
    return $content;

#7 @Denis-de-Bernardy
15 years ago

not really... foreach makes a copy of the the_content filters before running them, so this would only apply to the next post (see my comment above, it describes just that).

#8 @Denis-de-Bernardy
15 years ago

here's another related ticket, that highlights the use for such a hook: #1595

#9 @Denis-de-Bernardy
15 years ago

  • Keywords commit added

commit? wontfix?

#10 @jeremyclarke
15 years ago

  • Cc jer@… added

Gigantic +1, I can't believe this isn't already available.

#11 @ryan
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [11213]) Add the_post action. Props Denis-de-Bernardy. fixes #6284

Note: See TracTickets for help on using tickets.