I've built a website with Vehica - Car Dealer & Listing WordPress Theme and a Python script that adds car listings into a CSV file, and import that listings into my website on a schedule using WP All Import PRO, and also using WP All Import PRO to move listings to trash that are available in my website but not present into the import file. That way the website is fully automated, however sometimes I need to enter listings manually, not by import file, and those listings are moved to trash by WP All Import PRO scheduled removal, which I want to prevent. For that case, I created a checkmark for all listing "Do not delete", when it's selected the items marked with it should not be deleted by WP All Import PRO, however, there is something that I'm missing and instead of preventing WP All Import to move certain items to trash it skips all items, and doesn't work at all. Here is the code I use: // Add the meta box to custom post type edit screen function add_do_not_delete_meta_box() { add_meta_box( 'do_not_delete_meta_box', 'Не изтривай', 'render_do_not_delete_meta_box', 'vehica_car', // Replace with your custom post type slug 'side', 'high' ); } add_action('add_meta_boxes', 'add_do_not_delete_meta_box'); // Render the checkbox in the meta box function render_do_not_delete_meta_box($post) { // Retrieve the current value of the checkbox $value = get_post_meta($post->ID, '_do_not_delete', true); ?> <input type="checkbox" name="do_not_delete" value="1" <?php checked($value, '1'); ?> /> <label for="do_not_delete">Не изтривай</label> <?php } // Save the checkbox value function save_do_not_delete_meta_box($post_id) { // Verify if this is an auto save routine. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Check if the current user has permission to edit the post. if (!current_user_can('edit_post', $post_id)) { return; } // Update the meta field in the database. if (isset($_POST['do_not_delete'])) { update_post_meta($post_id, '_do_not_delete', '1'); } else { delete_post_meta($post_id, '_do_not_delete'); } } add_action('save_post', 'save_do_not_delete_meta_box'); // Prevent deletion during scheduled WP All Import removal add_filter('pmxi_delete_post', 'prevent_deletion_of_marked_items', 10, 2); function prevent_deletion_of_marked_items($id, $import) { // Check if the current post has the "do not delete" checkbox checked $do_not_delete = get_post_meta($id, '_do_not_delete', true); // If the checkbox is checked, prevent this item from being moved to trash if ($do_not_delete == '1') { return false; // Returning false prevents the deletion } return true; // Allow deletion if the checkbox is not checked } // Prevent deletion for manual removal via WP All Import or direct trashing add_action('before_delete_post', 'prevent_manual_trash_of_marked_items', 10, 1); function prevent_manual_trash_of_marked_items($post_id) { // Ensure this only runs on your custom post type if (get_post_type($post_id) === 'vehica_car') { $do_not_delete = get_post_meta($post_id, '_do_not_delete', true); // If the checkbox is checked, prevent this item from being moved to trash if ($do_not_delete == '1') { // Skip the trashing of this item remove_action('before_delete_post', 'prevent_manual_trash_of_marked_items'); wp_untrash_post($post_id); // Restore the post if it was accidentally moved to trash add_action('before_delete_post', 'prevent_manual_trash_of_marked_items'); return false; // Stop further deletion } } } // Additional protection for custom deletion actions (if applicable) add_action('wp_trash_post', 'check_and_prevent_trashing_marked_items', 10, 1); function check_and_prevent_trashing_marked_items($post_id) { // Ensure this only runs on your custom post type if (get_post_type($post_id) === 'vehica_car') { $do_not_delete = get_post_meta($post_id, '_do_not_delete', true); // If the checkbox is checked, prevent this item from being moved to trash if ($do_not_delete == '1') { remove_action('wp_trash_post', 'check_and_prevent_trashing_marked_items'); wp_untrash_post($post_id); // Restore the post if it was accidentally moved to trash add_action('wp_trash_post', 'check_and_prevent_trashing_marked_items'); return false; // Prevent the trashing } } }