I created a todo plugin and when I add a new todo, the title of the todo saves, but the details I write in the wysiwyg do not save and neither does the due date.

Here is the code I believe is responsible for the expected behavior in my-todo-list-fields.php:

function mtl_todos_save($post_id){
    $is_autosave = wp_is_post_autosave($post_id);
    $is_revision = wp_is_post_revision($post_id);
    $is_valid_nonce = (isset($_POST['wp_todos_nonce']) && wp_verify_nonce($_POST['wp_todos_nonce'], basename(__FILE__))) ? 'true' : 'false';

    if ($is_autosave || $is_revision || !$is_valid_nonce) {

    if (isset($_POST['priority'])) {
      update_post_meta($post_id, 'priority', sanitize_text_field($_POST['priority']));

    if (isset($_POST['details'])) {
      update_post_meta($post_id, 'details', sanitize_text_field($_POST['details']));

    if (isset($_POST['due_date'])) {
      update_post_meta($post_id, 'due_date', sanitize_text_field($_POST['due_date']));

  add_action('save_posts', 'mtl_todos_save');

I changed the $is_valid_nonce to !$is_valid_nonce, but that did not help.


The issue was in add_action('save_posts', 'mtl_todos_save');, instead it should be: add_action('save_post', 'mtl_todos_save');

Your Answer

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

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