Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created October 12, 2015 21:16
Show Gist options
  • Save strangerstudios/be666d7681118b30b875 to your computer and use it in GitHub Desktop.
Save strangerstudios/be666d7681118b30b875 to your computer and use it in GitHub Desktop.
Redirect non-members away from CPTs with specific term
<?php
function my_pmpro_term_template_redirect() {
global $post;
//change category and level ID here
if( has_term('my_category', 'category', $post) && !pmpro_hasMembershipLevel()) {
wp_redirect(pmpro_url('levels'));
exit;
}
}
add_action('template_redirect', 'my_pmpro_term_template_redirect');
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Restrict Access by Membership Level for Custom Post Type (CPT) Categories" at Paid Memberships Pro here: https://www.paidmembershipspro.com/restrict-access-by-membership-level-for-custom-post-type-cpt-categories/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment