tags:

views:

38

answers:

1

I recently had this code created for my Wordpress site. It makes it so that unregistered users can not see the newest posts available up to 15 days unless they register. It works, but I need it to only restrict one specific category in my Wordpress installation and not all of them (i.e. I need it to restrict this category but not my blog posts).

Can anyone tell me where and what is needed to make this code function this way? Thanks.

    add_filter('posts_where', '_custom_s2member_archive_filter');
function _custom_s2member_archive_filter($where) /* Require membership to view latest content. */
    {
        if(!is_admin() && (is_archive() || is_home()) && !current_user_can("access_s2member_level1"))
            {
                $where .= " AND post_date <= '".date ("Y-m-d", strtotime ("-15 days"))."'"; /* Back-date freeloaders. */
            }
        return $where;
    }
add_filter('template_redirect', '_custom_s2member_single_filter');
function _custom_s2member_single_filter() /* Require membership to view latest content. */
    {
        global $post; /* Need this for date comparison. */
        if(!is_admin() && is_single() && !current_user_can("access_s2member_level1"))
            {
                if(strtotime($post->post_date) > strtotime("-15 days"))
                    {
                        header("Location: ".S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL);
                        exit();
                    }
            }
    }
A: 

Start by figuring out what the ID of the category in question is. You can get that by going to Posts -> Categories in the Admin sidebar, then click on the category you're trying to restrict. The URL for the new page you are lead to will end in tag_ID=[some number]. That [some number] is the category ID.

Then use Wordpress's conditional tags to write an if statement like
if(is_category('[some number]'))
{
Put the code you already have for restricting the posts here
}

Granted, I have not tested this myself, but let me know how it works out!