0

I need to get the current PostID. I think in the function the postID is not existing yet. (Because save pre ...)

add_filter('content_save_pre', 'getImageUrlOutOfContent', 10, 1);

Am I right? How I can get the postID? Is there a better hook? I am updating the content (text) and uploading and adding a postImage.

Thank you

  • If it's a new post and you are looking to update the content before it's saved then it will not have a $post->ID yet. You'd need to allow the new post to be inserted into the DB, then get the resulting ID. – C C Jan 12 '16 at 14:54
  • ok - is there a hook list? Sorry I could't find one using google.... So in this case I set the postimage after saving ...?! – Patrick Jan 12 '16 at 15:19
0

There's no hook for "give me a post ID before the post has been created". You only get an ID after the post has been saved. So yes, use the hook 'content_save_pre' to modify your content before saving, then once you get back a post ID use that ID to update the post featured image.

There's a great answer describing how to acquire and set the image for a post, here

And, the hook you'd use to trigger that set image routine would be 'save_post' which is documented here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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