How do I get membership level id of a particular user. I have tried

$user = get_userdata($userid);
$membership_id = $user->membership_level->ID;

but it gives a notice of Trying to get property of non-object..... I am doing it through Ajax. I have googled it but does not found any solution. Anyone can help?

https://wordpress.org/plugins/paid-memberships-pro/

closed as off-topic by Mark Kaplun, Pieter Goosen, TheDeadMedic, Howdy_McGee, bueltge Apr 24 '16 at 8:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 2 down vote accepted

You probably want pmpro_getMembershipLevelsForUser from functions.php:

/* pmpro_getMembershipLevelsForUser() returns the membership levels for a user
 *
 * If $user_id is omitted, the value will be retrieved from $current_user.
 * By default it only includes active memberships.
 *
 * Return values:
 *      Success returns an array of level objects.
 *      Failure returns false.
 */
function pmpro_getMembershipLevelsForUser($user_id = NULL, $include_inactive = false)
{

Or there's pmpro_getMembershipLevelForUser if you only want the first level. Or if you actually want to test access then there's pmpro_hasMembershipLevel too.

As far as I can see these are all stored in separate tables with date ranges and other restrictions so there's no simple way to access them through normal WP user functions.

(And I expect there's documentation about all of these on their website here http://www.paidmembershipspro.com/documentation/ but it looks like you'll have to sign up.)

  • Yeah... I forgot to mention pmpro_getMembershipLevelForUser($user_id);. After watching my previous code I found this error. By the way thanks for your time. – PlanetHackers Apr 19 '16 at 13:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.