Title: Category Array Problem
Last modified: August 19, 2016

---

# Category Array Problem

 *  Resolved [GhostPool](https://wordpress.org/support/users/ghostpool/)
 * (@ghostpool)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/category-array-problem/)
 * I’m using the the following code for an is_category array, which works fine.
 *     ```
       <?php if(is_category(array(5,3,7))); ?>
   
       .....
   
       <?php } ?>
       ```
   
 * However whenever I replace 5,3,7 with a php tag ($theme_cats) to reference some
   category IDs written exactly like 5,3,7 it doesn’t work. I know $theme_cats works
   and when I echo the tag it returns 5,3,7. I assume I need to call the array in
   another way, can anyone help?
 *     ```
       <?php if(is_category(array($theme_cats))); ?>
   
       .....
   
       <?php } ?>
       ```
   

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

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/category-array-problem/#post-1338878)
 * So… `array(5,3,7)` is not the same as `$theme_cats = "5,3,7"; array($theme_cats);`.
   print_r() it and take a look.
 * The former is:
 *     ```
       Array
       (
           [0] => 5
           [1] => 3
           [2] => 7
       )
       ```
   
 * The latter is:
 *     ```
       Array
       (
           [0] => 5,3,7
       )
       ```
   
 * What you want to do is explode the string into an array, like so: `print_r(explode(',',
   $theme_cats));` Then you get this, which is what you want:
 *     ```
       Array
       (
           [0] => 5
           [1] => 3
           [2] => 7
       )
       ```
   
 *  Thread Starter [GhostPool](https://wordpress.org/support/users/ghostpool/)
 * (@ghostpool)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/category-array-problem/#post-1338910)
 * Works like a charm. Thanks very much apljdi. 🙂

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

The topic ‘Category Array Problem’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [GhostPool](https://wordpress.org/support/users/ghostpool/)
 * Last activity: [16 years, 5 months ago](https://wordpress.org/support/topic/category-array-problem/#post-1338910)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
