最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - Error when moving custom post type to bin

matteradmin10PV0评论

I am creating my first WP plugin and I'm having a some issues when trying to move a custom post type to the bin.

I have a custom post type and in this I have a custom meta box with four fields. I can see, save and permanently delete my data through the WP admin without problem but when I try moving a post to the bin I get an Undefined Index error against each of my fields. My code that saves the post data and where the error occurs is as follows:

function save_glass_types_admin($post_id, $post, $update) {

    if( !$update ) {
        return;
    }

    $glass_group         = sanitize_text_field($_POST['glass_group']);
    $glass_colour        = sanitize_text_field($_POST['glass_colour']);
    $glass_colour_ref    = sanitize_text_field($_POST['glass_colour_ref']);
    $glass_image_url     = sanitize_text_field($_POST['glass_image_url']);

    update_post_meta($post_id, 'glass_group', $glass_group);
    update_post_meta($post_id, 'glass_colour', $glass_colour);
    update_post_meta($post_id, 'glass_colour_ref', $glass_colour_ref);
    update_post_meta($post_id, 'glass_image_url', $glass_image_url);
}

I am calling this function from the index.php as follows:

add_action('save_post_glass-types', 'save_glass_types_admin', 10, 3);

I also have an include here:

include('process/save_post.php');

Please can anyone help show me where I am going wrong?

Many thanks in advance.

Post a comment

comment list (0)

  1. No comments so far