Using URL group to restrict access to custom post type

Hello, I was reading some earlier questions from other users and trying to use the URL Groups to restrict access to a Custom Post type. I had the idea that I should be able to do this with a URL group since I believe all posts in the post-type will start the the same URL. (Correct me if I’m missing something obvious)

I’m looking at the instructions on the installation page, but I can’t quite see what is going on exactly in the screenshot – might be blurry – might be my brain being blurry…

I have successfully restricted access to the archive page for the custom post type “newspaper” by entering this URL into a group:

http://jasandbox.ca/bannerpost/newspaper/

But I can’t figure out what to add after the slash to restrict the individual posts themselves.

is it newspaper/* or newspaper/.* ??

I tried looking at the regular expressions info page and I’m just not smart enough to figure that all out.

  • jageo
    • Flash Drive

    OK, sorry, I’ve figured it out. But will explain if it helps anyone else googling the same question.

    The screenshot shows /newspaper/.*

    So in full I am using these two URLs in my group:

    http://jasandbox.ca/bannerpost/newspaper/.*

    http://jasandbox.ca/bannerpost/newspaper/

    And I didn’t realize that the .* was the regular expression – so I turned the dropdown to YES (If any of the page URLs are regular expressions then set this to yes.)

    I’ve tested successfully. So this might be a viable suggestion to those who want to know how to protect a custom post type.

    Support staff please reply if there is anything needing clarification or extension. If I’m not seeing far enough ahead and will find a pothole, please advise :slight_smile:

    JA

  • DavidM
    • DEV MAN’s Mascot

    Hi JA,

    Glad you got that sorted and yep, that definitely seems the proper way to add those in with regular expressions. Thanks too for posting your solution back here, I’m sure others will find that very helpful. I’ve given you a few rep points for providing that helpful information! :slight_smile:

    Thanks,

    David

  • jageo
    • Flash Drive

    Curses! I am my own worst enemy.

    It occurred to me as I was styling the pages that it would be very encouraging to visitors to subscribe if they could see the archive-newspapers.php page – the list of newspapers (with a feature image and excerpt description), and the membership plug in could stop them from seeing the individual posts

    So what would you have in the URL Group if you wanted the user to be able to see the archive page for the post type ‘newspaper’?

    Using this: http://jasandbox.ca/bannerpost/newspaper/.* stops them from seeing /newspaper/

    Is there a way to structure the regular expression so it leaves the base URL out of the restriction?

  • jageo
    • Flash Drive

    But I can’t have a negative rule with URL Group and a positive rule with URL Group on the same access level. Rats, I’ll have to read up on these ‘regular expressions’ creatures. There must be some way to indicate that there must be more than one character after the slash.

    I’ll post back if I find something :slight_smile:

  • jageo
    • Flash Drive

    Woot! Got it working again. Found a regular expressions cheat sheet here

    Using a plus sign indicates 1 or more wildcard characters to follow.

    So my negative rule URL Group now says:

    http://jasandbox.ca/bannerpost/newspaper/.+

    I’ve tested it successfully. My visitor can see the archive page for the custom post type ‘newspaper’, but when they click on an issue, they are brought to the Subscription Page.

    This is a really slick solution now for protecting, but still promoting the content of a custom post type.

    I have a log in form in the sidebar of the archive page, instead of on the home page so the user is not logging in any sooner than they need to be, and I’m not wasting valuable advertising space on the front page. I think I’ll also make a demo or sample newspaper available on the archive page so a visitor can make sure they like the interface before they buy. Just this one change above makes for a whole better user experience.

    Very happy, thanks for the help

    JA

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.