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 );
}
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');
amendment – that snippet did work. Issue closed
Thanks for letting me know @katiehartrick, glad to hear you have figured this out.
@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.
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?
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.
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/
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.