I have a category that(using a plugin) is member only. What happens if a post is given a category that is member only, and a category that is available to everyone? If it is still accessible to everyone, how can I prevent that?

1 Answer
1

I tested it, and by default it will show it to everyone even if one of the categories is member only. If you need a fix for that(like me), then use the following in functions.php:

function my_filter( $content ) {

    $categories = array(
        'news',
        'opinions',
        'sports',
        'other',
    );

    if ( in_category( $categories ) ) {
        if ( is_logged_in() ) {
            return $content;
        } else {
            $content="<p>Sorry, this post is only available to members</p>";
            return $content;
        }
    } else {
        return $content;
    }
}
add_filter( 'the_content', 'my_filter' );

from my other question.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *