WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Restrict access to categories by user role (6 posts)

  1. thesammon
    Member
    Posted 1 month ago #

    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!

  2. Nate Defosses
    Member
    Posted 1 month ago #

  3. thesammon
    Member
    Posted 1 month ago #

    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.

  4. Nate Defosses
    Member
    Posted 1 month ago #

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

  5. jessicarenee408
    Member
    Posted 1 month ago #

    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/

  6. thesammon
    Member
    Posted 1 month ago #

    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!

Reply

You must log in to post.

About this Topic