你可以在save_post_
钩住,试试看:
add_action("save_post_" . CUSTOM_POST_TYPE, function ($post_ID, \\WP_Post $post, $update) {
if (!$update) {
update_post_meta($post->ID, "cx_number", "default value");
return;
}
if (isset($_POST["cx_number"])) {
update_post_meta($post->ID, "cx_number", $_POST["cx_number"]);
}
}, 10, 3);