How to determine current membership status with multiple membership records
I’m trying to create a section that lists the current membership status of a user.
So, I initially thought that just finding the record with the latest start date would give me the current membership record. However, I found that in some cases there are multiple membership records created in the
wp_pmpro_memberships_userstable for the same user with the same start date and time.
For example, if a user subscribes to a level and then one year later manually renews the subscription, there will be a second membership created with the old membership start date and we’ll have two records for this user, for example:
- id: 1, user_id: 10, start_date: 2017-01-21, status: changed
- id: 2, user_id: 10, start_date: 2017-01-21, status: active
and loading the current status by start date could show me “changed” instead of “active”.
So, my question is – is there a better value to use to find the current/latest membership record of the user?
I’m considering using one of these options:
- id – just get the record with the last id for the user
- combination of start date + id
- modified date
- The topic ‘How to determine current membership status with multiple membership records’ is closed to new replies.