Title: Restrict content based on post type
Last modified: July 19, 2021

---

# Restrict content based on post type

 *  Resolved [katie](https://wordpress.org/support/users/katiehartrick/)
 * (@katiehartrick)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/)
 * I have several custom post types and want to show/ hide restricted pages based
   on post type.
 * I know I can set “Filter Searches and Archives” to either yes or no. On this 
   site, I want to be able to show posts and pages, while hiding them on custom 
   post types.
 * What is the best way to achieve this?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [katie](https://wordpress.org/support/users/katiehartrick/)
 * (@katiehartrick)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14678266)
 * In settings i’ve set Filter Searches and Archives to No. My custom post type 
   is called “stories”.
 * Looks like I need to add a filter to amend this existing function from `paid-
   memberships-pro/includes/content.php`
 *     ```
       $pmpro_search_filter_post_types = apply_filters( 'pmpro_search_filter_post_types', array( 'page', 'post' ) );
       if ( ! is_array( $pmpro_search_filter_post_types ) ) {
       	$pmpro_search_filter_post_types = array( $pmpro_search_filter_post_types );		
       }
       ```
   
 *  Thread Starter [katie](https://wordpress.org/support/users/katiehartrick/)
 * (@katiehartrick)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14678489)
 * I’ve tried adding this function to child theme functions.php, the locked stories
   posts are still showing when user is locked out.
 *     ```
       function pmpro_hide_stories( $post_types ) {
           $post_types[] = 'stories';
           return $post_types;
       }
       add_filter('pmpro_search_filter_post_types', 'pmpro_hide_stories');
       ```
   
 *  Thread Starter [katie](https://wordpress.org/support/users/katiehartrick/)
 * (@katiehartrick)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14678988)
 * amendment – that snippet did work. Issue closed
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14679600)
 * Thanks for letting me know [@katiehartrick](https://wordpress.org/support/users/katiehartrick/),
   glad to hear you have figured this out.
 *  Thread Starter [katie](https://wordpress.org/support/users/katiehartrick/)
 * (@katiehartrick)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14682743)
 * [@andrewza](https://wordpress.org/support/users/andrewza/) I need to reopen this,
   during testing I switched “Filter searches and archives?” to **yes**. I’ve switched
   it back to **no** and the stories CPT is showing in search results.
 * Related question – is there a way to exclude member pages using a WordPress query?
   To date, my solution is tagging non-member pages with a specific category and
   filtering the query using that category.
    -  This reply was modified 4 years, 10 months ago by [katie](https://wordpress.org/support/users/katiehartrick/).
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14693106)
 * Sure that’s no problem at all. To confirm, you want to exclude post categories
   from this filtering when searching?
 * So for example, restricted posts that have category “X” will show, while restricted
   posts with category “Y” will be hidden?
 *  Thread Starter [katie](https://wordpress.org/support/users/katiehartrick/)
 * (@katiehartrick)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14698545)
 * There seems to be a misunderstanding. I have already created a CPT query and 
   filtered it to show a set category.
 *     ```
       $args = array(
        'category_name' => 'public',
        'order'    => 'title',
        'post_type'      => 'stories',
        'posts_per_page' => -1
       );
       ```
   
 * This relies on web authors setting all public posts to a specific category. **
   My question is, is there a way to filter the query to specifically hide PMPro
   membership posts?** Or is the only way to hide PMPro membership posts from the
   query is to ensure all public posts have a specific category set (in this example`
   public`)
 * I’ve read using `post__not_in` leads to performance issues, and setting a category
   to exclude means setting another parameter in addition to setting PMPro membership.
 *  Plugin Author [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * (@andrewza)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14701155)
 * Did the snippet mentioned earlier on to add your CPT to the filter for searches
   and archives? Is it not hiding the content once you’ve added the snippet previously
   mentioned. The built in filter Paid Memberships Pro does, includes categories
   as well as any posts that have the “Require Membership” options selected and 
   hides it accordingly – [https://www.paidmembershipspro.com/filtering-members-only-content-in-home-archives-searches-and-widgets/](https://www.paidmembershipspro.com/filtering-members-only-content-in-home-archives-searches-and-widgets/)
 * We do try to keep this as optimized as possible.
 * I recommend reaching out to a local WordPress developer to assist you with writing
   the optimized solution here.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Restrict content based on post type’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/paid-memberships-pro_f1dacb.svg)
 * [Paid Memberships Pro - Content Restriction, User Registration, & Paid Subscriptions](https://wordpress.org/plugins/paid-memberships-pro/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/paid-memberships-pro/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/paid-memberships-pro/)
 * [Active Topics](https://wordpress.org/support/plugin/paid-memberships-pro/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/paid-memberships-pro/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/paid-memberships-pro/reviews/)

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 8 replies
 * 2 participants
 * Last reply from: [Andrew Lima](https://wordpress.org/support/users/andrewza/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/restrict-content-based-on-post-type/#post-14701155)
 * Status: resolved