Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active November 10, 2023 18:26
Show Gist options
  • Save strangerstudios/7751640 to your computer and use it in GitHub Desktop.
Save strangerstudios/7751640 to your computer and use it in GitHub Desktop.
SQL to change the id of a Paid Memberships Pro level from old_id to new_id. Please BACKUP YOUR DATABASE FIRST, make sure to change the DB table names to match your prefix, and make sure that there is not another level with
# change these vars
SET @old_id = 2;
SET @new_id = 1;
# change the db table prefix here
UPDATE IGNORE wp_pmpro_membership_levels SET id = @new_id WHERE id = @old_id;
UPDATE IGNORE wp_pmpro_discount_codes_levels SET level_id = @new_id WHERE level_id = @old_id;
UPDATE IGNORE wp_pmpro_membership_orders SET membership_id = @new_id WHERE membership_id = @old_id;
UPDATE IGNORE wp_pmpro_memberships_categories SET membership_id = @new_id WHERE membership_id = @old_id;
UPDATE IGNORE wp_pmpro_memberships_pages SET membership_id = @new_id WHERE membership_id = @old_id;
UPDATE IGNORE wp_pmpro_memberships_users SET membership_id = @new_id WHERE membership_id = @old_id;
@chiptesters
Copy link

chiptesters commented Nov 10, 2023

This hasn't been updated in 10 years but I'm happy to report it mostly works though a few new tables were part of my installation at least.

Here's the code that I used:

SET @old_id = 1;
SET @new_id = 2;

UPDATE IGNORE wp_pmpro_membership_levelmeta SET pmpro_membership_level_id = @new_id WHERE pmpro_membership_level_id = @old_id;
UPDATE IGNORE wp_pmpro_membership_ordermeta SET pmpro_membership_order_id = @new_id WHERE pmpro_membership_order_id = @old_id;
UPDATE IGNORE wp_pmpro_membership_levels SET id = @new_id WHERE id = @old_id;
UPDATE IGNORE wp_pmpro_memberships_categories SET membership_id = @new_id WHERE membership_id = @old_id;
UPDATE IGNORE wp_pmpro_membership_orders SET membership_id = @new_id WHERE membership_id = @old_id;
UPDATE IGNORE wp_pmpro_memberships_pages SET membership_id = @new_id WHERE membership_id = @old_id;
UPDATE IGNORE wp_pmpro_memberships_users SET membership_id = @new_id WHERE membership_id = @old_id;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment