Question about Membership 2 Pro

I'm trying to find the location of the page level Membership 2 Pro Access information in the MySQL database. In the page editor there's the "Membership Access" panel where you can give access to a page based on the membership level. I would like to find where that information is stored in the database.

  • Adam Czajczyk
    • Support Gorilla

    Hello John,

    I hope you're well today and thank you for your question!

    These information are stored in the database in the wp_postmeta table and it's not that easy to interact with them directly on a database level.

    First thing to know is the ID of the post/page. That one you can see in browser address bar when editing post/page or you can fetch it in your plugin/theme with a core WP function, e.g. this one (if it's within WP loop): get_the_ID().

    Knowing that you could search the wp_postmeta table by "meta_value" field for "%ID%" (where ID = the post/page ID that you found earlier); note the % characters wrapping around the numerical ID - that's important because otherwise you won't find any data as the value is a serialized array.

    Such search should return a bunch of rows with where "meta_key" is "rule_values". There might be only one but there may also be more. Furthermore, there's no guarantee that it will actually related to only Membership 2 Pro (as, in theory, some other plugin may also use such meta_key).

    Assuming that it is related to Membership 2 Pro, the value of "post_id" of these rows would tell you with what memberships the post/page is protected.

    It would be better, however, to search the table by both "post_id" and "meta_value" columns where "search value" for "post_id" column would be a numberical ID of a selected membership and the "search value" for "meta_value" column would be as described above. This way you'd be sure that you actually found the rows that really apply to the Membership 2 Pro protection.

    That being said, I'm not sure what do you need it for, but if you want to somehow check/manipulate memberships/protection rules directly, omitting plugin interface (e.g. via some code of your own) it would be much better to use Membership 2 Pro APi in my opinion. You'll find documentation for it directly in the plugin on "Membership 2 -> Help -> API Docs" page in your site's dashboard.

    Best regards,
    Adam

  • John
    • New Recruit

    Hello Adam,

    Thanks for all of this information! It's super helpful - especially when you mentioned that the information was included in the API. I didn't realize that, and after looking at the request's response I see it and I'm going to use that to avoid accessing the meta data directly.

    Thanks again.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.