Membership 2 Pro protected content

I want to output a post by custom query while the post is protected by Membership 2 Pro. But unable to do it. Is there any way to get around it? I want to show the post in the search.

  • Dimitris
    • Support Star

    Hello there fonderco,

    hope you're doing well today!

    We removed protected post via the pre_get_posts hook, so you can check the following code in this MU Plugin, which is used for showing protected posts in archives:

    If you're finding troubles with it, please do share your custom code so we can have a better picture. As our support forums are publicly available, if you don't want to do that publicly, just let us know here in your next reply. :slight_smile:

    Warm regards,

  • fonderco
    • Design Lord, Child of Thor

    I see how that code removes the pre_get_posts filter, but I don't want to remove that filter permanently. Only inside of another plugin.

    I'm using the plugin WP Courses ( as I need a basic course taking system. I would CoursePress but it is just too detailed. Each of my courses consists of a single video. In CoursePress I have to make a unit and a module and just through 10 hoops to create a basic course that only has a single lesson.


    WP Courses has 2 custom post types. "courses" which basically allow the user to see an overview and "lessons" which are the actual content.

    In Membership2, I have protected the "lesson" custom post type.

    Now to the issue.

    Lessons have a custom field with the ID of the course they are associated with. So, on the single course page to know which lesson to start them on... The plugin uses WP_Query to find the lesson that has the custom field equal to the course's post_id.

    Because lessons are protected this query is always empty.

    $args = array(
    'post_type' => 'lesson',
    'meta_value' => $course_id,
    'meta_key' => 'wpc-connected-lesson-to-course',
    'posts_per_page' => 1,
    'paged' => false,
    'nopaging' => true,
    'order' => 'ASC',
    'orderby' => 'menu_order'

    $query = new WP_Query($args);

    $course_link = get_the_permalink();

    How to replicate this issue:

    1. Install Membership2 and create a membership
    2. Install WP Courses and create a course with a lesson
    3. Be logged out and view the course and then click "Start" to start the lesson
    4. You will be taken to register, don't register
    5. Now protect the "lesson" custom post type
    6. Be logged out and view the course and then click the "Start" button - it doesn't take you anywhere because it doesn't know the lesson to send you to

  • Tho Bui
    • Staff

    Hi fonderco,

    I hope you're well today!

    I have prepared a custom snippet which you can use as a guide here :

    You can download a zip, unzip it and upload file m2p-wp-course-fix-issue-connect-lesson.php to your wp-content/mu-plugins folder. If that folder doesn't exist you can simply create it.

    If you are not familiar with mu-plugins you can read about them here:
    or you can paste it in your child theme's functions.php file.

    Kind regards,
    Tho Bui

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.