Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Created September 17, 2020 18:46
Show Gist options
  • Save ronalfy/1c70899ca337bca74b0cf2374022582e to your computer and use it in GitHub Desktop.
Save ronalfy/1c70899ca337bca74b0cf2374022582e to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Set Start and End Dates
/**
* Show SQL query examples for setting a start and end date for users without one.
*
* PLEASE BACK UP YOUR DATABASE FIRST BEFORE ATTEMPTING ANY OF THESE QUERIES
*/
/* Get users with no end date - Useful for checking how many there are */
select * from wp_pmpro_memberships_users where enddate is NULL OR enddate = '0000-00-00 00:00:00'
/* Get users with no start date - Useful for checking how many there are */
select * from wp_pmpro_memberships_users where startdate is NULL OR startdate = '0000-00-00 00:00:00'
/* Set start date as same time as user registration */
UPDATE wp_pmpro_memberships_users mu
LEFT JOIN wp_users u ON mu.user_id = u.ID
SET mu.startdate = u.user_registered
WHERE mu.startdate IS NULL
/* Set end date to arbitrary date */
UPDATE wp_pmpro_memberships_users
SET enddate = '2020-01-01 00:00:00'
WHERE status = 'active'
AND ( enddate IS NULL
OR CAST(enddate AS CHAR(20)) = '0000-00-00 00:00:00' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment