0

I am using this code to update post meta but it is not working.

function run_when_job_published( $post_id, $post, $update){
   $post_meta = get_post_meta($post_id);
}
add_action('save_post_jobs', 'run_when_job_published', 10, 3);

But here in this function $post_meta is returning an empty array. Actually I want to update one of the meta field during post insertion but I think it is not possible with this hook. I have also tried publish_post hook but in my scenario it is not working. Any suggestion will be much appreciated. Thank you!

  • that looks to be right. remove global $post and see if the $post variable being passed in is what you're expecting it to be. same with the $post_id variable – mrben522 Dec 21 '18 at 19:51
  • Yes I am getting correct values from "$post" and "$post_id" but not able to get data from post meta. – Awan Dec 21 '18 at 20:15
  • Meta data hasn’t been saved yet when the action fires, try looking in $_POST – Milo Dec 21 '18 at 23:29
  • @Milo for your suggestion. I will try this. – Awan Dec 21 '18 at 23:41
  • i think this is action problem – vikrant zilpe Dec 22 '18 at 9:41

Your Answer

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

Browse other questions tagged or ask your own question.