[wp-hackers] Best practice for early access of post data

Mike Little wordpress at zed1.com
Sun Sep 18 16:15:56 UTC 2011

On Sun, Sep 18, 2011 at 04:05, Claude Needham <gxxaxx at gmail.com> wrote:

> On Sat, Sep 17, 2011 at 6:17 PM, Mike Schinkel
> <mikeschinkel at newclarity.net> wrote:
> > On Sep 17, 2011, at 8:54 PM, Claude Needham wrote:
> >> Is there a proper way to get a peek at the data from the post(s)
> >> without messing up the loop -- and who knows how many plugins and
> >> filters?
> >
> > The 'posts_results' hook will show you the array of posts and the query
> object immediately after it runs the query.  Does that help?
> >
> > -Mike
You might also want to look into the 'body_class' filter. Most css
customisation based on the contents of the page can be done by simply adding
a class to the body tag.

If I want to peek at the content of the loop for the purposes of modifying
something in the theme (usually in the header), I hook onto
action 'template_redirect', which is suitably late in the process,
but guaranteed to be before any theme code has run (apart from earlier hooks
from functions.php). I can safely loop through the results detect/extract
what I need, then rewind_posts() when I've finished to put everything back.

Mike Little

More information about the wp-hackers mailing list