Title: the_posts hook problem
Last modified: August 18, 2016

---

# the_posts hook problem

 *  [realwx](https://wordpress.org/support/users/realwx/)
 * (@realwx)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/the_posts-hook-problem/)
 * I can’t get this plugin working. The main object of this plugin is to block guests
   from viewing any post in a set category via plugin file. I’ve set category number
   as 1. This is my first plugin, so don’t yell at me!
 * <?php
    /* Plugin Comments removed for posting on WordPress.org */
 * $my_cat = “1”;
 * function applysubbyposts($the_posts) {
    global $wpdb; if(!is_user_logged_in()){
   foreach($the_posts as $key => $post) { $thiscat = $wpdb->get_var(“SELECT category_id
   FROM post2cat WHERE post_id=’$post->ID'”); if(floatval($thiscat) == floatval(
   $my_cat)) unset($the_posts[$key]); } } return $the_posts; } add_filter(“the_posts”,“
   applysubbyposts”); ?>

The topic ‘the_posts hook problem’ is closed to new replies.

## Tags

 * [guest](https://wordpress.org/support/topic-tag/guest/)
 * [hide](https://wordpress.org/support/topic-tag/hide/)
 * [hook](https://wordpress.org/support/topic-tag/hook/)
 * [the_posts](https://wordpress.org/support/topic-tag/the_posts/)
 * [view](https://wordpress.org/support/topic-tag/view/)

 * 0 replies
 * 1 participant
 * Last reply from: [realwx](https://wordpress.org/support/users/realwx/)
 * Last activity: [19 years, 1 month ago](https://wordpress.org/support/topic/the_posts-hook-problem/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
