Opened 5 years ago
Closed 4 years ago
#6284 closed enhancement (fixed)
add a the_post hook
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.8 |
| Component: | Optimization | Version: | 2.5 |
| Severity: | normal | Keywords: | has-patch tested commit |
| Cc: | jer@… |
Description
Could we add a the_post hook, fired when the_post() gets called?
Its absence led me to this bug while investigating a workaround:
http://trac.wordpress.org/ticket/6283#preview
Thanks -- D
Attachments (1)
Change History (12)
Denis-de-Bernardy
— 4 years ago
comment:3
Denis-de-Bernardy
— 4 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.
comment:5
Denis-de-Bernardy
— 4 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.
comment:6
azaozz
— 4 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;
}
comment:7
Denis-de-Bernardy
— 4 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).
comment:8
Denis-de-Bernardy
— 4 years ago
here's another related ticket, that highlights the use for such a hook: #1595
comment:10
jeremyclarke
— 4 years ago
- Cc jer@… added
Gigantic +1, I can't believe this isn't already available.
comment:11
ryan
— 4 years ago
- Resolution set to fixed
- Status changed from new to closed
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.