WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

This should work within your function:

get_post_field( 'post_parent', $id )
share|improve this answer
Nice! Thanks much. – two7s_clash May 24 '11 at 18:00

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.

share|improve this answer
This hook is being used inside the editor, fyi. – two7s_clash May 24 '11 at 18:00

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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.