The code recipe below sets membership restriction on a Custom Post Type (CPT) category. When a non-member visits a CPT in a protected category (either a logged out visitor or a logged in user without membership access) they will be redirected to the membership levels page (or another page as defined in your custom function).

How it Works

You can update the code recipe with appropriate membership levels to check, the CPT categories you want to redirect, and the page that the non-member gets redirected to. You can even duplicate the recipe to account for multiple CPT category and level/redirect page relationships.

pmpro_cpt-events-demoLets say, for example, you are using an events plugin. You could set a category of event for “Members Only”, then use this recipe to redirect non-members to a sales page for membership to join these events.

Or, you may be using a directory plugin that you list special partner offers for members only. You could set a category of these “premium offer” listings that require membership.

Just want to restrict single CPTs?

If you want to restrict your Custom Post Type at the singular level, use the Custom Post Type Membership Access add on.

The Code Recipe

This code recipe requires a PMPro Plus Account or higher.

View Membership Options

Comments (6)

Hi guys, fantastic plugin, I have it working nearly the way I would like it but I have 1 issue.

I would like all my custom categories/taxonomies to list in the ‘Edit Membership Level’ > Content Setting > (default post) Categories, I managed to get my CPT categories/taxonomies to display here but when I checked the CPT categories it had no effect, I did this through the get_categories( apply_filters( ‘pmpro_list_categories_args’, $args ) ); and adding my taxonomy

What am I missing? any help would be appreciated

Just to add the above, I also checked the pmpro_memberships_categories tables and all of the CPT taxonomies I ticked is listed in the tables next to the corresponding Membership levels

Category restrictions in PMPro only apply to the ‘post’ post_type. You’ll need to extend the content filters to apply to your unique CPT post_type. If you open a ticket in the support area we will help with this customization.


At line 5, when calling the pmp_hasMembershipLevel function I’d like to fetch the list of Level assigned to that category and then pass it in as a parameter. We have a lot of membership levels and a lot of categories, so manually passing id’s doesn’t scale in the short or long term, as adding new levels would require us to update our code base.

Is there a method available for returning all levels assigned to a category? If not, if I wrote one, could it be included as part of the PMP codebase and maintained going forward so I don’t have to worry about the SQL used falling behind as PMPpro is updated?

Thanks, and a fast response appreciate, we actively are evaluating this product as a long term solution.

I was able to tackle this a different route that worked in my instance, where I needed to redirect any post a user shouldn’t be able to access to a new template vs the default logic:

ID, NULL, false) ) {
add_action(‘template_redirect’, ‘my_pmpro_term_template_redirect’);

We don’t have a method, but you can get an array of level ids that have access to an array of categories like this:

$membership_ids = $wpdb->get_col(“SELECT membership_id FROM $wpdb->pmpro_memberships_categories WHERE category_id IN(‘” . implode(‘,’, $category_ids) . “‘”);

Hope this helps. If not, we can help you to write up a more specific bit of code in our member forums.

Leave a Reply

For faster support related to issues on your specific site please open a ticket in our members support area.

Your email address will not be published. Required fields are marked *