12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Oct 27, 2021

Getting Posts Restricted to Enabled Memberships for the Current User with WP-Members in Oxygen

Sridhar Katakam

In the WPDevDesign Facebook group a user asks:

Hi guys!

I am building a membership website where the user has access to coruses if they sign up for a membership. I am using WP-members for this. Sridhar Katakam already created a similar tutorial but i am unable to find out how i can modify this for my use-case.

My goal is to create a dashboard page where the user can see the courses (Courses is the CPT) which he/she has access. Has anybody created a query like this for WP-members. Sridhar Katakam could you help me (and maybe other subscribers of your tutorials) to customize your code for what i am looking for? Thank you guys!

and the ensuing conversation:

In this premium tutorial we shall use pre_get_posts in a Code Block above the Repeater to filter the posts to those that are restricted to WP-Members' memberships that the currently logged-in user has access to.

For example, let's say there are "Beginner" and "Intermediate" and "Advanced" membership products.

"User A" has been assigned to "Beginner" and "Intermediate" memberships.

Then there's a "Course" CPT where

  • "Course A" item is set to be visible to only those that have "Beginner" membership and
  • "Course B" item is set to be visible to only those that have "Intermediate" membership and
  • "Course C" item is set to be visible to only those that have "Advanced" membership

The objective is to list all the courses that User A has access to. In this case, these would be Courses A and B. Other logged-in users should similarly see the courses that they have access to across all their memberships.

Here's how.

In the Oxygen editor, add a Section and inside that a Code Block.


This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.