Only add the event category if it finds the correct id
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 24 Apr 2017 19:22:16 +0000 (15:22 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 24 Apr 2017 19:22:16 +0000 (15:22 -0400)
If it returns false then don't insert a record for it.

models/front/events/icalFeedImport.php

index eaa1390..532b430 100644 (file)
@@ -271,14 +271,17 @@ class GlmMembersFront_events_icalFeedImport
                 if ( isset( $event['CATEGORIES'] ) ) {
                     $category_data = explode( ',', $event['CATEGORIES'] );
                     foreach ( $category_data as $category ) {
-                        $this->wpdb->insert(
-                            GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
-                            array(
-                                'event'    => $event_id,
-                                'category' => $this->getCategoryId( $category )
-                            ),
-                            '%d'
-                        );
+                        $categoryId = $this->getCategoryId( $category );
+                        if ( $categoryId ) {
+                            $this->wpdb->insert(
+                                GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'event_categories',
+                                array(
+                                    'event'    => $event_id,
+                                    'category' => $categoryId
+                                ),
+                                '%d'
+                            );
+                        }
                     }
                 }
                 // Location Data