Example #1
0
 /**
  * Save data on POST
  *
  * @since   1.0
  * @param   int    $post_id
  * @return  void
  */
 public function save_data($post_id)
 {
     parent::save_data($post_id);
     $tax_input = isset($_POST['cas_condition']['tax_input']) ? $_POST['cas_condition']['tax_input'] : array();
     //Save terms
     //Loop through each public taxonomy
     foreach ($this->_get_taxonomies() as $taxonomy) {
         if (current_user_can($taxonomy->cap->assign_terms)) {
             //If no terms, maybe delete old ones
             if (!isset($tax_input[$taxonomy->name])) {
                 $terms = null;
             } else {
                 $terms = $tax_input[$taxonomy->name];
                 //Hierarchical taxonomies use ids instead of slugs
                 //see http://codex.wordpress.org/Function_Reference/wp_set_post_terms
                 if ($taxonomy->hierarchical) {
                     $terms = array_unique(array_map('intval', $terms));
                 }
             }
             wp_set_object_terms($post_id, $terms, $taxonomy->name);
         }
     }
 }