With PMPro, you can optionally hide all member-only content from your site’s main blog page, category and other archive pages, as well as from search.

When you have your settings configured this way, site visitors will not see protected content while browsing your site. Additionally, logged in members will not see content that is unavailable for their level.

In this code recipe post, we show you how to add back some specific categories to show up in your searches and archives. This is a useful approach if you have some members-only content that you’d like to appear while non-members are browsing your site, while other category content should be excluded.

Banner for Advanced Code Recipe Tutorial for Paid Memberships Pro

Understanding the pre_get-posts Filter

WordPress’ pre_get_posts filter offers a way to modify the query used to return posts. For example, on the category archive for a category named “Dog Content”, the WordPress query parameters are set up to return only posts in the “Dog Content” category.

PMPro core uses this same hook to remove members-only content from the query. We use this filter to make sure that the content being returned from the query doesn’t include members-only content—all based on your Advanced Settings for filtering searches and archives.

About the Code Recipe

For this code recipe, we run a later filter on the pre_get_posts hook to add some “not hidden category” IDs back into the query.

These category posts are still locked to members-only, but instead of being stripped out from view, they will show up in the regular loop of posts. It’s a great way to include some posts as teaser content for your membership.

The Code Recipe

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.

Update the array of $not_hidden_cat_ids on line 19 for your specific category IDs to add back into the search and archive pages.

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.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo