Skip to main content
added 35 characters in body
Source Link

The following worked for me. You need to hook yourI hooked my meta saving and retrieving to the same action (post_transition_status), but with different priorities.

//Save Your Custom Meta Meta, but hook it to transition_post_status instead of save_post, with a priority of 1
function save_yourpost_meta(){
  global $post;
      if($post -> post_type == 'your_post_type') {
          update_post_meta($post->ID, "your_meta_key", $_POST["your_meta_key"]);
      }
  }
add_action('transition_post_status', 'save_yourpost_meta',1,1);


//Then retrieve ityour custom meta only when the post is saved for the first time, not on updates. Hooked to the same action, with a lower priority of 100

function get_meta_on_publish($new_status, $old_status, $post) {
if('publish' == $new_status && 'publish' !== $old_status && $post->post_type == 'your_post_type') {
  //Get your meta info
  global $post;
  $postID = $post->ID;
  $custom = get_post_custom($postID);
  //You have your custom now, have fun.
  
  }
}
add_action('transition_post_status', 'get_meta_on_publish',100,3);

I hope this helps!

The following worked for me. You need to hook your meta saving and retrieving to the same action, with different priorities.

//Save Your Custom Meta Meta, but hook it to transition_post_status instead of save_post, with a priority of 1
function save_yourpost_meta(){
  global $post;
      if($post -> post_type == 'your_post_type') {
          update_post_meta($post->ID, "your_meta_key", $_POST["your_meta_key"]);
      }
  }
add_action('transition_post_status', 'save_yourpost_meta',1,1);


//Then retrieve it only when the post is saved for the first time, not on updates. Hooked to the same action, with lower priority of 100

function get_meta_on_publish($new_status, $old_status, $post) {
if('publish' == $new_status && 'publish' !== $old_status && $post->post_type == 'your_post_type') {
  //Get your meta info
  global $post;
  $postID = $post->ID;
  $custom = get_post_custom($postID);
  //You have your custom now, have fun.
  
  }
}
add_action('transition_post_status', 'get_meta_on_publish',100,3);

I hope this helps!

The following worked for me. I hooked my meta saving and retrieving to the same action (post_transition_status), but with different priorities.

//Save Your Custom Meta Meta, but hook it to transition_post_status instead of save_post, with a priority of 1
function save_yourpost_meta(){
  global $post;
      if($post -> post_type == 'your_post_type') {
          update_post_meta($post->ID, "your_meta_key", $_POST["your_meta_key"]);
      }
  }
add_action('transition_post_status', 'save_yourpost_meta',1,1);


//Then retrieve your custom meta only when the post is saved for the first time, not on updates. Hooked to the same action, with a lower priority of 100

function get_meta_on_publish($new_status, $old_status, $post) {
if('publish' == $new_status && 'publish' !== $old_status && $post->post_type == 'your_post_type') {
  //Get your meta info
  global $post;
  $postID = $post->ID;
  $custom = get_post_custom($postID);
  //You have your custom now, have fun.
  
  }
}
add_action('transition_post_status', 'get_meta_on_publish',100,3);

I hope this helps!

Source Link

The following worked for me. You need to hook your meta saving and retrieving to the same action, with different priorities.

//Save Your Custom Meta Meta, but hook it to transition_post_status instead of save_post, with a priority of 1
function save_yourpost_meta(){
  global $post;
      if($post -> post_type == 'your_post_type') {
          update_post_meta($post->ID, "your_meta_key", $_POST["your_meta_key"]);
      }
  }
add_action('transition_post_status', 'save_yourpost_meta',1,1);


//Then retrieve it only when the post is saved for the first time, not on updates. Hooked to the same action, with lower priority of 100

function get_meta_on_publish($new_status, $old_status, $post) {
if('publish' == $new_status && 'publish' !== $old_status && $post->post_type == 'your_post_type') {
  //Get your meta info
  global $post;
  $postID = $post->ID;
  $custom = get_post_custom($postID);
  //You have your custom now, have fun.
  
  }
}
add_action('transition_post_status', 'get_meta_on_publish',100,3);

I hope this helps!