From e4d3191f7966ebaf4aba157bf80595781bfc79c2 Mon Sep 17 00:00:00 2001 From: weryques Date: Wed, 9 May 2018 18:01:16 -0300 Subject: [PATCH] Fixes (issue #33): TypeError: undefined is not an object (evaluating 'i.replace') --- src/classes/repositories/class-tainacan-fields.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/classes/repositories/class-tainacan-fields.php b/src/classes/repositories/class-tainacan-fields.php index 640095b3a..7d23ea0be 100644 --- a/src/classes/repositories/class-tainacan-fields.php +++ b/src/classes/repositories/class-tainacan-fields.php @@ -648,6 +648,8 @@ class Fields extends Repository { * @param $collection_id * @param $field_id * + * @param string $search + * * @return array|null|object * @throws \Exception */ @@ -670,18 +672,23 @@ class Fields extends Repository { if( strpos( $field->get_field_type(), 'Core_Title') !== false ){ $title = $item->get_title(); - if(stristr($title, $search)) { + if(!empty($search) && stristr($title, $search) !== false) { + $return[] = [ 'item_id' => $item->get_id(), 'field_id' => $field_id, 'mvalue' => $title ]; + } elseif (empty($search)) { $return[] = [ 'item_id' => $item->get_id(), 'field_id' => $field_id, 'mvalue' => $title ]; } } else { $description = $item->get_description(); - if(stristr($description, $search)) { + if(!empty($search) && stristr($description, $search) !== false) { + $return[] = [ 'item_id' => $item->get_id(), 'field_id' => $field_id, 'mvalue' => $description ]; + } elseif (empty($search)) { $return[] = [ 'item_id' => $item->get_id(), 'field_id' => $field_id, 'mvalue' => $description ]; } } } + $results = []; if (!empty($return)) { $results[] = $return; }