From f3c6969db0d3aaefb0dfdadb5676093610bbab62 Mon Sep 17 00:00:00 2001 From: Nathan Pitman Date: Sun, 3 Aug 2014 23:14:25 +0100 Subject: [PATCH] Should fix #10 --- .../ft.nf_categories_field.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/system/third_party/nf_categories_field/ft.nf_categories_field.php b/system/third_party/nf_categories_field/ft.nf_categories_field.php index d95ae86..09eef35 100644 --- a/system/third_party/nf_categories_field/ft.nf_categories_field.php +++ b/system/third_party/nf_categories_field/ft.nf_categories_field.php @@ -450,7 +450,12 @@ public function save($data) { public function post_save($data) { - $selected_cats = array_filter(explode($this->settings['delimiter'], $data)); // array_filter removes empty nodes + if (!empty($data)) { + // array_filter removes empty nodes + $selected_cats = array_filter(explode($this->settings['delimiter'], $data)); + } else { + $selected_cats = array(); + } // Just to be sure... if ($this->settings['sync_cats']) { @@ -459,8 +464,12 @@ public function post_save($data) { $this->EE->db->select('cat_id'); $this->EE->db->where('entry_id', $this->settings['entry_id']); $current_cats_array = $this->EE->db->get('category_posts')->result_array(); - foreach($current_cats_array AS $current_cat) { - $current_cats[] = $current_cat['cat_id']; + if (!empty($current_cats_array)) { + foreach($current_cats_array AS $current_cat) { + $current_cats[] = $current_cat['cat_id']; + } + } else { + $current_cats = array(); } // Trash cats is current cats minus any selected cats