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…
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.EDIT: Do NOT forget to escape and properly sanitize input data! Else you will open a security hole.