Title: Multidimensional Array Question
Last modified: August 19, 2016

---

# Multidimensional Array Question

 *  [jessedrelick](https://wordpress.org/support/users/jessedrelick/)
 * (@jessedrelick)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/multidimensional-array-question/)
 * Hello,
 * I have a custom content type ‘products’. Instead of using the custom taxonomies,
   I decided to store the Category and Subcategory as Post Meta. What I want to 
   do is create a drop down menu with categories and subcategories:
 *     ```
       global $post;
       $categories= array();
   
       $product_categories = new WP_Query();
       $product_categories->query('post_type=products&posts_per_page=10000');
       while($product_categories->have_posts()) : $product_categories->the_post();
       $post_id= $post->ID;
       $category= get_post_meta($post_id, 'category', true);
       $subcategory= get_post_meta($post_id, 'subcategory', true);
       $categories[$category]= array();
       array_push($categories[$category], $subcategory);
       endwhile;
       print_r($categories);
       ```
   
 * The above code will output:
 * Array ( [Plastic Liners & Film] => Array ( [0] => Steel Pail Liners ) [Stormwater
   Management] => Array ( [0] => Drain Guards ) [Spill Containment] => Array ( [
   0] => Spill Pallets ) [Sorbents & Spill Kits] => Array ( [0] => Oil-Only Sorbents)[
   Drums & Containers] => Array ( [0] => Steel Pails ) [HazMat Containers] => Array([
   0] => Accessories ) )
 * It does what I want, but it will only add one subcategory, even though there 
   are several. How can I get around this?
 * Much thanks…

The topic ‘Multidimensional Array Question’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [jessedrelick](https://wordpress.org/support/users/jessedrelick/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/multidimensional-array-question/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
