diff --git a/entityreference.module b/entityreference.module
index 170ac8c..5f46782 100644
--- a/entityreference.module
+++ b/entityreference.module
@@ -694,6 +694,9 @@ function entityreference_field_widget_form(&$form, &$form_state, $field, $instan
     $autocomplete_path .= '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/';
     if ($entity) {
       list($id) = entity_extract_ids($entity_type, $entity);
+      if (!$id) {
+        $id = 0;
+      }
       $autocomplete_path .= $id;
     }
 
@@ -801,7 +804,7 @@ function entityreference_autocomplete_callback($type, $field_name, $entity_type,
     return MENU_ACCESS_DENIED;
   }
 
-  $entity = $entity_id !== '' ? entity_load_single($entity_type, $entity_id) : NULL;
+  $entity = $entity_id ? entity_load_single($entity_type, $entity_id) : NULL;
   $handler = entityreference_get_selection_handler($field, $instance, $entity_type, $entity);
 
   if ($type == 'tags') {
