Title: in_category using array
Last modified: August 20, 2016

---

# in_category using array

 *  [budster2k1](https://wordpress.org/support/users/budster2k1/)
 * (@budster2k1)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/in_category-using-array/)
 * I am trying to check if a title exists within a specific categories I want duplicate
   titles as long as they are in different categories. I think I need to use in_category
   with and array as the post_ID comparing if any of the post_ids are in the array.
   Thanks for any help.
 *     ```
       global $wpdb;
       if ($posts = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_title = '".mysql_real_escape_string($title)."' && post_status = 'publish'", 'ARRAY_A')) {
         if (in_category($cat, $posts) == 1) {
           //Do Nothing
         } else {
           //Do Something
         }
       }
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/in_category-using-array/#post-2508570)
 * see ‘Examples’ in [http://codex.wordpress.org/Function_Reference/in_category](http://codex.wordpress.org/Function_Reference/in_category)
 *  Thread Starter [budster2k1](https://wordpress.org/support/users/budster2k1/)
 * (@budster2k1)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/in_category-using-array/#post-2508585)
 * `print_r ($posts)`
    returns `Array ( [0] => Array ( [ID] => 4071 ) [1] => Array([
   ID] => 7741 ) )` I am wondering how to use this information to check all the 
   ID’s in the array to see if they belong to a category and if any of the ID’s 
   are in the specific category skip that post. But when I use $posts the comparison
   does not find any matching ID’s even though there are some. I think it has to
   do with the two level array but I don’t know how to get this to a single array
   that can be processed in the in_category function. Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘in_category using array’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [in_category](https://wordpress.org/support/topic-tag/in_category/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [budster2k1](https://wordpress.org/support/users/budster2k1/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/in_category-using-array/#post-2508585)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
