Title: Save Metabox Data Looping Through an Array
Last modified: August 21, 2016

---

# Save Metabox Data Looping Through an Array

 *  [Alessio Lo Vecchio](https://wordpress.org/support/users/youon/)
 * (@youon)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/save-metabox-data-looping-through-an-array/)
 * Hi all,
 * I’ve a metabox for a specific custom post type (Stores), inside the metabox I
   create a variable amount of checkboxes based on a WP_Query. In other words I 
   have many checkboxes as the children pages (Armani, Gucci, Versace, …) of a specific
   page (Brands).
 *     ```
       function add_stores_metabox() {
   
           add_meta_box(
               'store-brands',
               'Store Brands',
               'display_brands_stores_metabox',
               'stores',
               'side',
               'high'
           );
   
       }
   
       function display_brands_stores_metabox() {
   
           $args = array(
               'post_type' => 'page',
               'post_parent' => 43
               );
   
           $brands_in_stores = new WP_Query($args);
   
           while ($brands_in_stores->have_posts()) : $brands_in_stores->the_post();
   
               global $post;
   
               wp_nonce_field( plugin_basename( __FILE__ ), 'brands_stores_nonce' );
   
               $title = get_the_title();
               $html = '<p>';
               $html .= '<input id="' . $post->post_name . '" type="checkbox" name="' . $post->post_name . '" value=""/>';
               $html .= '<label for="' . $post->post_name . '">' . $title . '</label>';
               $html .= '</p>';
   
               echo $html;
   
           endwhile; wp_reset_query();
       }
       ```
   
 * Now the UI works fine, but I don’t know how to save these data looping through
   an array, because I’ve to find dynamically the name of the field to use the update_post_meta()
   in the saving function that will follow.
 * Someone could helps me?

The topic ‘Save Metabox Data Looping Through an Array’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [Alessio Lo Vecchio](https://wordpress.org/support/users/youon/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/save-metabox-data-looping-through-an-array/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
