Protected custom post type with Membership 2 Pro but I can't see a list of posts

I have a custom post type called "Lessons", all posts are listed on a page called "Drum lessons". Using Membership 2 Pro I have protected the Lessons CPT, however, I notice that when I protect it, none of the posts show on the page where they are all listed.

I would like to still be able to list all the posts and then when a user goes to read more they are shown the protected content message.

I am custom coding the template to display all my lesson posts, is there something I can add so that I can still list them even when they are protected?

    • Samuel

      Thanks for your reply Milan
      Since I'm custom coding the template, would it be possible to wrap the template in code that protects what I want to protect on the page?

      Currently I am using this:

      <?php echo do_shortcode('[ms-protect-content]'); ?>
                            // show video
                            $video_url = get_post_meta($post->ID, '_video_url', true); ?>
                            <div class="lesson_video">
                                <?php echo wp_oembed_get($video_url); ?>
                            <?php echo do_shortcode('[/ms-protect-content]'); ?>

      With the intention of hiding the "lesson_video" from non-members. However, this shows both the video and the text "The content you are trying to access is only available to members. Sorry.

      Have I done something wrong here?

  • awesurance

    I'm experiencing this same issue. I have a Custom Post Type that I would like to restrict access to paid subscribers and it seems to show content hard coded into the template, but it does not display any content stored in the database (the actual custom post). It also does not show a list, but only one instance of the blank template.

    I'm considering trying to wrap the content I want to protect in a shortcode, like Samuel suggested up top.

    Did you guys find a fix for this issue?


  • Adam Czajczyk

    Hello Samuel, hello awesurance!

    The Membership 2 Pro plugin includes a template tag that can be used in a template instead of "do_shortcode()" function.

    The template tag is:


    An ID of a membership (or a list of IDs separated by comma) may be passed to the function as well. With no ID it will check whether the current user has any membership and with ID passed to it it will check for the specific membership. It will return boolean value of "true" or "false".

    Given that, the code from Samuel's example could look like this (checking for any membership):

    <?php  if ( ms_has_membership() ): ?>
        // show video
        $video_url = get_post_meta($post->ID, '_video_url', true); ?>
        <div class="lesson_video">
             <?php echo wp_oembed_get($video_url); ?>
     <?php endif; ?>

    This should output the video if a user is a member of any membership. In order to check for specific membership you would want to replace the first line

    <?php if ( ms_has_membership() ): ?>

    with this (where "100" should be replaced with ID of a selected membership):

    <?php  if ( ms_has_membership(100) ): ?>

    or for multiple memberships:

    <?php  if ( ms_has_membership(100,101,102) ): ?>

    I hope that helps :slight_smile:

    Best regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.