2

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?

closed as off-topic by Dave Romsey, kraftner, Max Yudin, cjbj, Rarst Jul 26 '17 at 12:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Depends on how your plugin manages this. Since a) we don't know the name of the plugin and b) are not plugin support, well, this is impossible to answer – kero Jul 22 '17 at 0:43
2

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.