[wp-hackers] getting post_id at plugin load time

David House dmhouse at gmail.com
Mon Apr 4 09:02:40 GMT 2005


On Apr 4, 2005 8:20 AM, Brett Taylor <brett at webfroot.co.nz> wrote:
> Hi all,
> 
> I need to write a cookie out at plugin load time, and the value of this
> cookie is related to the current post id and whether or not it's in
> comments display mode... $post doesn't exist at this time. :(
> 
> Any idea how to get this information at this time?

My best idea would be to add a hook in yourself, in
wp-blog-header.php. Search for 'query_posts', then in the next line,
add this:

do_action('post_query_posts');

Then you can hook onto this from inside your plugin:

function write_cookie() {
  //your code goes here
}

add_action('post_query_posts', 'write_cookie');

That won't be called as soon as your plugin is loaded, but it will be
executed as soon as $post is created.

-- 
-David House, dmhouse at gmail.com


More information about the wp-hackers mailing list