How to Restrict Content Access Based on Subscription Date in WordPress

Imagine this: You’re running an exclusive online magazine. Subscribers sign up to get access to new and future issues, but you don’t want them snooping around older content published before they joined. It’s like giving someone a key to your latest treasure chest without letting them unlock the ones that were buried before they arrived.

Sounds tricky, right? Well, not really! In this post, I’ll show you how you can set up a WordPress membership site where subscribers can only access content published after their subscription date. No coding genius required—just a bit of guidance and some clever use of WordPress hooks, custom fields, and the mighty Groundhogg CRM plugin.

Let’s dive in!

Why Would You Want to Restrict Content by Date?

Here’s a real-world example: Let’s say you’re running a digital magazine that publishes monthly issues. When someone subscribes in October, they only get access to October’s issue and everything published after that. They shouldn’t be able to view issues from September or earlier.

This setup is perfect for:

  • Subscription-based blogs or magazines
  • Online courses with rolling enrollment dates
  • Membership sites offering time-sensitive content

The goal is to dynamically control access to your content without manually tagging or managing users for every single post. With a bit of automation magic, you can make it work seamlessly.

The Solution: Custom Fields + WordPress Login

We’ll use Groundhogg to store the subscription date for each user in a custom meta field. Then, we’ll tweak WordPress to do the heavy lifting: filtering out old content and restricting access to individual posts.

Here’s the step-by-step breakdown:

Step 1: Capture the Subscription Date

First, we need to record the date when a user subscribes. This is where Groundhogg comes in handy.

  1. Set up a Groundhogg Funnel:
    • Add a Benchmark (e.g., when a user submits a form or a tag is applied).
    • Add an Edit Meta action.
    • Create a custom meta field called subscribe_date and set its value to {meta.date_created}.

Now, every time a new user subscribes, their subscription date will be saved automatically.

Step 2: Filter Posts in the Archive

Next, we make sure users only see posts published after their subscription date when browsing the archive (e.g., a list of all issues).

Add the following code to your theme’s functions.php file:

add_action('pre_get_posts', function ($query) {
    if (!is_admin() && $query->is_main_query() && is_post_type_archive('issues')) {
        if (is_user_logged_in()) {
            $user_id = get_current_user_id();
            $subscribe_date = get_user_meta($user_id, 'subscribe_date', true);

            if ($subscribe_date) {
                $subscribe_date_obj = new DateTime($subscribe_date);
                $formatted_date = $subscribe_date_obj->format('Y-m-d');

                $query->set('date_query', array(
                    array(
                        'after' => $formatted_date,
                        'inclusive' => true,
                    ),
                ));
            }
        } else {
            wp_redirect(home_url('/login'));
            exit;
        }
    }
});

Here’s what this code does:

  • It checks if the user is viewing the archive for your custom post type issues.
  • If the user is logged in, it grabs their subscribe_date and filters the posts to only show those published after that date.
  • If the user isn’t logged in, they’re redirected to the login page.

Step 3: Restrict Access to Individual Posts

What if someone tries to access a single post (e.g., /issues/issue-001) directly? We’ll handle that too by verifying their subscription date before showing the content.

Add this code to functions.php:

add_action('template_redirect', function () {
    if (is_singular('issues')) {
        if (is_user_logged_in()) {
            $user_id = get_current_user_id();
            $subscribe_date = get_user_meta($user_id, 'subscribe_date', true);

            if ($subscribe_date) {
                global $post;
                $post_date = new DateTime(get_the_date('Y-m-d', $post));
                $subscribe_date_obj = new DateTime($subscribe_date);

                if ($post_date < $subscribe_date_obj) {
                    wp_die(
                        '<h1>Access Denied</h1><p>Oops! This issue was published before your subscription started. You don’t have access to this content.</p><a href="' . home_url() . '">Go back to the homepage</a>',
                        'Access Denied',
                        array('response' => 403)
                    );
                }
            }
        } else {
            wp_redirect(home_url('/login'));
            exit;
        }
    }
});

This code:

  • Checks if the user is viewing a single issues post.
  • Compares the post’s publication date with the user’s subscription date.
  • If the post is too old, it displays a friendly “Access Denied” message (or redirects them elsewhere).

Step 4: Customize the User Experience

Want a nicer error page? Instead of using wp_die(), you can redirect users to a custom page like /access-denied that explains why they can’t view the content.

wp_redirect(home_url('/access-denied'));
exit;

Create a WordPress page at /access-denied with your custom message and branding.

Step 5: Test, Test, Test!

Before rolling this out, make sure everything works as expected. Test these scenarios:

  • A new subscriber can only see posts published after their subscription date.
  • Older subscribers can still access older posts.
  • Non-logged-in users are redirected to the login page.

Wrapping Up

And there you have it! With a bit of WordPress magic and Groundhogg’s automation, you’ve built a dynamic content restriction system that keeps your exclusive content… well, exclusive. 🎩✨

This setup is perfect for subscription-based businesses, online courses, or anyone delivering time-sensitive content. Plus, it’s fully automated, so you can focus on creating amazing content instead of manually managing user access.

If you found this tutorial helpful, let me know in the comments—or share your own creative use cases for this setup. Happy coding!

Kontakt

Tarife

Klein

8

1 Domain inklusive:
DE

1 E-Mail Adressen

3 Mail-Aliases

1 Website

mBuild Sitebuilder

10 GB Speicherplatz

Mittel

15

1 Domain inklusive:
DE

3 E-Mail Adressen

10 Mail-Aliases

1 Website

mBuild & EasyWP

20 GB Speicherplatz

Groß

25

1 Domain inklusive:
DE

10 E-Mail Adressen

Unlimited Mail-Aliases

1 Website

mBuild, EasyWP & WP-Pro

50 GB Speicherplatz

Klein

60

Spare 37,50%

1 Domain inklusive:
DE

1 E-Mail Adressen

3 Mail-Aliases

1 Website

mBuild Sitebuilder

10 GB Speicherplatz

Mittel

110

Spare 38,89%

2 Domains inklusive:
DE / EU

3 E-Mail Adressen

10 Mail-Aliases

1 Website

mBuild & EasyWP

20 GB Speicherplatz

Groß

180

Spare 40%

3 Domains inklusive:
DE / EU / AT / CH

10 E-Mail Adressen

Unlimited Mail-Aliases

1 Website

mBuild, EasyWP & WP-Pro

50 GB Speicherplatz