• Hi all!

    please, maybe anyone knows how to retrieve de postID in a “image_send_to_editor” hook function???

    :::sample code:::

    add_filter(‘image_send_to_editor’, array($this,’w3f_crop_upload’));

    function w3f_crop_upload($metadata) {
    //global $wp_query;
    //$thePostID = $wp_query->post->ID; ??? I don’t kwow why, but this doesn’t work ???

    // need the POST_ID!!
    $thumb1 = get_post_meta($this->postid, ‘w3f-Img1’);
    return $metadata;
    }

    Thank you for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The attachment_id, which is the post ID of the attachment itself, is the post ID. If you’re looking for which post that attachment appears in, you’d have to run a query, but $attachment_ID might be what you’re looking for.

    function edit_image_html(html, $attachment_id, $attachment) {
      // do something useful in here
    }
    add_filter('image_send_to_editor', 'edit_image_html', 10, 3);

    If you needed the post, you could do this:

    function edit_image_html(html, $attachment_id, $attachment) {
      $post = &get_post($attachment_id);
      // do something useful in here
    }
    add_filter('image_send_to_editor', 'edit_image_html', 10, 3);

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Retrieve postID in a image_send_to_editor hook function’ is closed to new replies.