1

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.

3 Answers 3

2

This should work within your function:

get_post_field( 'post_parent', $id )
1
  • This seems to get the id of the post which originally uploaded the image, not the current post being edited.
    – Naltroc
    Commented Jul 26, 2018 at 16:51
0

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.

1
  • This hook is being used inside the editor, fyi. Commented May 24, 2011 at 18:00
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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