I hooked to add_attachment, and I want to add custom field to the parent post with the URL of the new attachment.
I am using this code:
$attach_post_obj = get_post($attach_ID);
// check if post is not a post, than return
$parent_post_obj = get_post($attach_post_obj->post_parent);
if ($parent_post_obj->post_type != 'post')
$url = wp_get_attachment_url($attach_ID);
add_post_meta($attach_post_obj->post_parent, 'full', $url);
The problem is that if upload before I save for the first time, the custom field is not added. It’s as if the post_parent field is not initialized yet.
Anything I can do about it? Or maybe I should hook somewhere else?
BTW, I am using the new v2.3
The topic ‘add custom field to parent post while adding attachment’ is closed to new replies.