Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

3 Answers 3

up vote 0 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

 
discard

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.