WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Restrict access to categories by user role

[Resolved] Restrict access to categories by user role

  • I’m trying to set up a website with posts and pages split into two categories: Residential and Commercial, with users split into the two different groups as well (either using custom fields, or custom user roles). Users in the Residential group should not be able to see any content in the Commercial group, and vice versa. I am using the Pods plugin to assign a category to a page.

    I’ve spent nearly all day trying to figure out how to do this, but thus far have come up with nothing. It would be preferable to do this with a plugin, as I have rather limited knowledge in PHP, though if that’s not possible at the moment, I definitely understand.

    I am certainly open to alternative methods as well, so long as they accomplish the same goal.

    Any help or assistance would be much appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • This absolutely doesn’t answer the question. In addition to being rather rude, that search doesn’t turn up anything relating to hiding content in certain categories from certain groups of users.

    You found NO ANSWER to your problem in those search results?
    I did, no problem.
    This one, especially

    First… I would create two new user roles by adding this to your functions.php file

    function custom_roles() {
    	global $wp_roles;
    	add_role(
    		'commercial_user',
    		__('Commercial User'),
    		array(
    	        'read'         => true,  // true allows this capability
    	        'edit_posts'   => false,
    	        'delete_posts' => false, // Use false to explicitly deny
    	    )
    	);
    	add_role(
    	    'residential_user',
    		__('Residential User'),
    		array(
    	        'read'         => true,  // true allows this capability
    	        'edit_posts'   => false,
    	        'delete_posts' => false, // Use false to explicitly deny
    	    )
    	);
    }
    add_action('after_setup_theme', 'custom_roles');

    Then you can use the Restrict categories plugin to easily choose what categories each role can access:

    http://wordpress.org/plugins/restrict-categories/

    That “Restrict Categories” plugin is exactly what I’m looking for, thanks.

    I found a better solution for assigning categories to pages than what I was using before, as well. Hopefully this will work.

    Thanks for your assistance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Restrict access to categories by user role’ is closed to new replies.
Skip to toolbar