WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to read the custom fields set by the user when publishing a new post:

function doSomething($post) {

   $meta = get_post_meta($post->ID);

   error_log("post meta: ".print_r($meta, true));


add_action("new_to_publish", "doSomething", 999);
add_action("draft_to_publish", "doSomething", 999);
add_action("pending_to_publish", "doSomething", 999);

The custom fields are there for draft_to_publish but not for new_to_publish.

If I use save_post it seems to work every time, but I need it to only run when the status is set to publish for the first time...

share|improve this question
That's because the fields weren't set then. For e.g. Autosave doesn't save them, etc. Use the values from $_POST instead for your "new_to_publish" action. – kaiser Sep 18 '12 at 7:53
Thanks @kaiser, didn't think to check $_POST. It worked great. – Andreyu Sep 18 '12 at 8:17
up vote 2 down vote accepted

That's because the fields weren't set then. Note: The »Autosave« process/request also doesn't save them.

Use the values from $_POST instead for your "new_to_publish" action.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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