This guide outlines the process to redirect users from empty category or tag archives to the levels page.

Why would the category archive or tag archive be blank? In Paid Memberships Pro, we offer a setting to filter members-only content from the search results or archives pages. If all posts in a specific category are protected, there would be no results.

Use this code recipe to redirect users to your pricing page (or another page of your choice) when they can’t access that content.

Banner image for Rediredt Empty Category or Tag Archive When All Posts Are Members-Only

About the Code Recipe

First, check how your site is set up:

  1. Navigate to the Memberships > Settings > Advanced screen in the WordPress admin.
  2. Locate the Filter searches and archives setting.
  3. Check your setting for this field: Yes or No.

If your setting is “Yes – Only members will see restricted posts/pages in searches and archives”, this means that non-members may land on an empty post archive page. Consider using this recipe to make your member experience less confusing.

This code snippet checks if the user is on a category or tag archive page with no posts available—meaning that PMPro is filtering all of the protected stuff from the results.

If true, the user will automatically redirect to the levels page. This prevents users from landing on empty pages, which could lead to confusion or a negative perception of the site.

Screenshot of PMPro Demo Pricing Page

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.

You can customize the code to redirect to your levels page or location of your choice. Adjust the $redirect_url parameter to set this to another page.

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