plugin development - Error when moving custom post type to bin

admin2025-06-06  3

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749200060a317202.html

最新回复(0)