How to retrieve the postID in a “image_send_to_editor” hook function?

Here is my function:

function insert_img_rel_attrib( $html, $id, $caption, $title, $align, $url  )
{
  $postID = ???
  $rel = "<a rel='shadowbox[".$postID."]'";
  if ($url) {$html = str_replace("<a",$rel,$html);}
  return $html;
}
add_filter( 'image_send_to_editor', 'insert_img_rel_attrib', 10, 6 );

How do I get the current post ID? I’ve tried the obvious, global $wp_query;
$postID = $wp_query->post->ID;
etc.

Related posts

Leave a Reply

3 comments

  1. Your global should work, what happens when you echo $postID ( you should probably use a more unique name here).

    You can also try,

    global $post;
    $Your_Post_ID = $post->ID;
    

    I am not very familiar with this hook though, you might have to use wpdb.

  2. From what I recall, the global $post isn’t set in the thickbox. You can check the contents of the global $_REQUEST though, and retrieve it from there (assuming that the editor is being called from a post editing screen and not through the media manager or some other location).