Paid Memberships Pro has a few ways to natively protect your posts: by category, tag, and per single post.
If you’re using custom code or a plugin that adds a custom post taxonomy, this guide will show you how to add post protections to those custom terms used in your site.
What are Taxonomies and Terms?
In a default WordPress site, you can create posts and assign them to any number of Categories or Tags. Both of these post fields help you organize your content and structure your data.
Categories and tags are two examples of what WordPress calls a Taxonomy: “a way of grouping posts together based on a select number of relationships” (source WordPress.org).
You’re probably closely familiar with categories and tags, but WordPress taxonomies extend way beyond these two built-in features. Your site can include other taxonomies that get added via plugins and your theme. You may have even created your own taxonomies via custom code.
In the code example below, we show you how a recipe website can protect posts by a custom taxonomy called “Dietary Requirements”. Within this taxonomy, the site has terms such as “Gluten Free”, “Keto,” and “Vegan”.
Adjust and use the code below to protect content by your custom post taxonomy. For example, to offer content specifically to your Keto Members, unique from the content accessed by members in your Vegan level.
The Code Recipe (PHP)
Adding the Recipe to Your Website
You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.
The main portion of this code that you must customize is the multidimensional array on lines 23 to 30.
- In the
$term_levels
array, add a new empty array where thekey
is the unique taxonomy name for each taxonomy you need to protect. - Within each taxonomy array, add a new empty array where the
key
is the unique term name for each term within the taxonomy. - Finally, set the value to each term in your custom code to an array of level IDs that have access to view items with this term in this taxonomy.
In the example code above, the dietary_requirement
custom taxonomy for the term named Keto
is restricted for logged-in members with level ID 1 or 2.
Please Note: This code overrides any other PMPro-related access for restricted terms.
For example, if a post requires Level 1, but has a tag that restricts the post for Level 2, the code here blocks Level 1 members and only allows access to members with Level 2.
The code can be modified to stop the override, however you must adjust the logic on a case-to-case basis.
PMPro: We Love Being Extendable
We often express that the best part of PMPro (and WordPress as a platform) is our intentional commitment to customizability and extendability.
Your WordPress site is completely unique—there is no other WordPress site exactly like yours. The built-in taxonomies you may be using (or not using!) plus the custom taxonomies added by other plugins or code are all uniquely yours.
While Paid Memberships Pro natively supports post restrictions by category, tag, and per single post, there are many more ways you can extend PMPro for restricting content. Check out this guide on all the 28 ways you can protect access to content in your WordPress site for more information.
Need some help? Our support team is here to assist you in getting this code (and any other recipe we offer) working for your membership site.
Free Course: Membership Site Development—The Basics
Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.