I'm updating a plugin from WP 2.3 to 2.6. Trying to get the current $post_id when running a function as the "upload_dir"-filter. This is what I've tried so far:
global $post_id;
global $post; $post_id = $post->ID;
global $wp_query; $post_id = $wp_query->post->ID;
None of these produce the post id. Is the global scope somehow disabled in WP 2.6? How can I get the $post_id?
The $post does not get set until the Loop has begun. You can't get a post ID when there isn't one, and the upload_dir is not used when there is one.
Thanks Otto42. Just to be clear: the plugin has worked well up until to 2.5. I've always had a global $post_id; to play with.
File uploads are handled on the Write Post screen and they are attached to the active post; obviously there must be a post_id somewhere...
Well... A post doesn't have an ID until you have saved it. So I don't see how a post_id could be set anywhere.
I'll look at it, see what I can figure out.
Finally realized today that I could just check the $_REQUEST variable and see what was being passed around. Sure enough - the current post ID was there.
$post_id = $_REQUEST['post_id'];