Skip to content

Commit

Permalink
Should fix #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Pitman committed Aug 3, 2014
1 parent 2274f22 commit f3c6969
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions system/third_party/nf_categories_field/ft.nf_categories_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand All @@ -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
Expand Down

0 comments on commit f3c6969

Please sign in to comment.