Title: [Plugin: Restrict Categories] Restricting categories for users programmatically
Last modified: August 20, 2016

---

# [Plugin: Restrict Categories] Restricting categories for users programmatically

 *  [acoelhosantos](https://wordpress.org/support/users/acoelhosantos/)
 * (@acoelhosantos)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-restrict-categories-restricting-categories-for-users-programmatically/)
 * Let me start by saying good job in this plugin. For me, it works perfectly and
   I have no problems with it.
 * I was now wondering if besides the normal admin page, if there is a defined way
   for restricting categories through php code (programmatically). My intent is 
   to automatically restrict categories when a user registers in the site.
 * Thanking you in advance for any help.
 * [http://wordpress.org/extend/plugins/restrict-categories/](http://wordpress.org/extend/plugins/restrict-categories/)

Viewing 1 replies (of 1 total)

 *  [valuser](https://wordpress.org/support/users/valuser/)
 * (@valuser)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-restrict-categories-restricting-categories-for-users-programmatically/#post-2945313)
 * Would playing around with this be of any help
 *     ```
       function onlyinclude_tag($query) {
       if ( $query->is_home() && is_user_logged_in()) {
       	$query-> set('category__in',array('green'));
       	}
       return $query;
       }
       add_filter('pre_get_posts','onlyinclude_tag');
       ```
   
 * Change the if conditions and the category (green) to suit you
 * and place function in the functions.php of your theme
 * see also [http://codex.wordpress.org/Class_Reference/WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query)
 * May help

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Restrict Categories] Restricting categories for users programmatically’
is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/restrict-categories.svg)
 * [Restrict Categories](https://wordpress.org/plugins/restrict-categories/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/restrict-categories/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/restrict-categories/)
 * [Active Topics](https://wordpress.org/support/plugin/restrict-categories/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/restrict-categories/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/restrict-categories/reviews/)

## Tags

 * [how-to](https://wordpress.org/support/topic-tag/how-to/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [post categories](https://wordpress.org/support/topic-tag/post-categories/)
 * [programmatically](https://wordpress.org/support/topic-tag/programmatically/)

 * 1 reply
 * 2 participants
 * Last reply from: [valuser](https://wordpress.org/support/users/valuser/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-restrict-categories-restricting-categories-for-users-programmatically/#post-2945313)
 * Status: not resolved