[Membership 2 Pro] Membership access to custom post type not working

I need to add different membership levels to a custom post type that I've developed for the site. I've added it, but the CPT is still showing to non-members.

  • JC
    • WPMU DEV Initiate

    Hi Ash

    No, I don’t think that this is working correctly. I don’t want the pages to be protected. The pages are open for everyone to view, and the CPTs are displayed with a template within the pages, using the Membership 2 Pro shortcode. So it should display the page publicly, with some information viewable at the top, then the CPTs below should only be viewable to those that meet the membership criteria.

  • Kasia Swiderska
    • Support nomad

    Hello JC,

    Sorry about the delay.

    don’t want the pages to be protected.

    At the moment they are not. This is page http://dev2.focus-info.org/what-we-do/moving-to-the-uk/living-in-the-uk/education and it is not protected.

    The pages are open for everyone to view, and the CPTs are displayed with a template within the pages, using the Membership 2 Pro shortcode.

    We would need to see this template. Can you enable support access again and tell me the name of the template?

    kind regards,
    Kasia

  • JC
    • WPMU DEV Initiate

    This is a better example: http://dev2.focus-info.org/what-we-do/moving-to-the-uk/settling-in-the-uk/childcare

    On this page, you'll see the pink block with Greycoat Lumleys. This is using a CPT called Sponsor Resources, and should not be restricted. Ie, anyone visiting the page can see the page and this pink block.

    Further down the page is a block called Childcare Resources. These are pulling in a CPT called info_resources.

    You can see in Membership 2 > Custom Post Types that I've set the info_resource CPT to be accessed only by members of the FOCUS Membership. However, they are showing to anyone who visits the site.

    Both the CPTs and Templates are in Pods ADmin > Templates. The actual template is called 'Resources' - code is below.

    <li class="row listing__item">
      <div class="cells">
        <div class="cell">
          <p class="listing__title">{@post_title}</p>
    			<div class="listing__body">
            <p>{@post_content}</p>
    				[if named_contact]<p>Contact: {@named_contact}</p>[/if]
          </div>
          <p>
            [if phone]<span class="listing__phone item__details"><a class="item__phone" href="tel:"><strong>Phone:</strong> {@phone}</a></span>[/if]
    
            [if fax]<span class="listing__phone item__details"><a class="item__phone" href="tel:"><strong>Fax:</strong> {@fax}</a></span>[/if]
    
    				[if email]<span class="listing__email item__details"><a class="link item__details" href="mailto:">{@email}</a></span>[/if]
    
    		  [if address_1]<span class="listing__address item__details">{@address_1}[if address_2], {@address_2}[/if][if city], {@city}[/if] [if postcode], {@postcode}[/if] [if country] {@country}[/if]</span>[/if]</p>
    		<p>
    		 <span class="item__details link">
    			<a href="{@web_address}" class="link" target="_blank" rel="noopener noreferrer">Visit website</a>
    		</span>
    			</div>
    		</div>
    </li>
  • Kasia Swiderska
    • Support nomad

    Hello JC ,

    I saw your site, you have a different option enabled. You have default one, that allows protecting a whole custom post type. But that one works differently than the Add-on I proposed. This add-on protects individual posts instead of the whole type and then it should stop displaying them on archive pages and should also hide on your pages.

    kind regards,
    Kasia

  • JC
    • WPMU DEV Initiate

    It looks like by using this feature, I have over 400 pages of content to filter through, and no means of selecting the info_resource CPT posts en masse. Even selecting one page of them causes the site to bomb out.

  • Nithin
    • Support Wizard

    Hi JC,

    Hope you are doing good today. :slight_smile:

    It looks like by using this feature, I have over 400 pages of content to filter through, and no means of selecting the info_resource CPT posts en masse. Even selecting one page of them causes the site to bomb out.

    I just gave a quick look, and I could notice all the posts related to the info_resources CPT was displaying.

    However, when I try to assign a membership to these pages, it keeps on loading, and the membership wasn't getting assigned.

    Checking the browser console error, it's generated 500 internal server console errors. Maybe the system is running out of server resources, and hence the pages aren't getting assigned.

    To check what's causing the issue, you'll have to enable debug mode so that it would give a better idea about the issue.

    To enable debug mode, open your wp-config.php file located in your root directory, and look for define(‘WP_DEBUG’, false);. Change it to:

    define('WP_DEBUG', true);

    In order to enable the error logging to a file on the server you need to add:

    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    @ini_set( 'display_errors', 0 );
    define( 'SCRIPT_DEBUG', true );

    After making the above changes, please try to replicate the issue again by assiging a membership to the CPT page, the related errors will be saved to a debug.log log file inside the /wp-content/ directory.

    Please attach these in your next reply in txt format file, so that we could give a closer look. You can find more details about debugging here.

    Please let us know how that goes, have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • Ash
    • WordPress Hacker

    Hello JC

    500 and timeout errors are different. 500 means there is a fatal php error which is blocking the website from functioning.

    Would you please attach your wp-config.php here? Please REMOVE all the DB details from the wp-config.php and make a zip, then attach the file to your reply and we will check.

    Have a nice day!

    Cheers,
    Ash

  • JC
    • WPMU DEV Initiate

    Thanks Ash

    We've thrown more at the server, so no more 500 timeouts. However, I'm trying to remove a membership from the CPT and it's still saving - last time I checked the timer it had been going for over 45 minutes.

    Wp Config attached

  • Kasia Swiderska
    • Support nomad

    Hello JC ,

    This line is missing in wp-config.php

    define('WP_DEBUG', true);

    add it above those lines:

    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    @ini_set( 'display_errors', 0 );
    define( 'SCRIPT_DEBUG', true );

    like that:

    after that it should start logging errors in debug.log

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.