Query Users by Membership Subscription


I am using the Membership plugin to keep users in different "Subscriptions".

I need to batch update user metadata for every user within Subscription "X". Is there a meta_key I can use to query only users within Subscription "X" using WP_Query or WP_User_Query?

Thank you.

  • Vaughan
    • Support/SLS MockingJay

    Hi @bryan

    This i'm not so sure could be done with WP_Query you would probably need a custom query to do this.

    Something like

    $wpdb->query("UPDATE " . $wpdb->users . " as users, " . $wpdb->prefix . "m_membership_relationships as membership SET column = 'data' WHERE users.ID = $user_id AND users.ID = membership.user_id AND membership.sub_id = $subscription_id");

    But let me just ask the developer for some feedback on this for you, just in case.

    Hope this helps

    not exactly sure of the exact query as that would depend on what you're trying to update.

  • Vaughan
    • Support/SLS MockingJay

    Hi @Bryan

    Ok, so if you need to just get all user id's

    Then a query such as

    $query = $wpdb->get_results("SELECT ID FROM " .$wpdb->users . " AS users, " . $wpdb->prefix . "m_membership_relationships AS membership WHERE users.ID = membership.user_id AND membership.sub_id = '" . $subscription_id . "'")

    Should return all user_ids as an indexed array row objects.

    Hope this helps

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.