diff --git a/social_content/social_content.module b/social_content/social_content.module
index 5eed3bf..630771a 100644
--- a/social_content/social_content.module
+++ b/social_content/social_content.module
@@ -135,21 +135,33 @@ function social_content_cron() {
  *  The number of deleted nodes.
  */
 function social_content_delete_old_nodes() {
-
   $nids_to_delete = array();
   $instances = SocialContent::getAllInstances();
 
   foreach ($instances as $instance) {
-    if (isset($instance->settings['auto_delete'])
-      && is_numeric($instance->settings['auto_delete'])
+    if (isset($instance->settings['auto_delete']) && is_numeric($instance->settings['auto_delete'])
       && $instance->settings['auto_delete'] > 0) {
 
       // Get all ids and timestamps of nodes imported by this instance.
-      $nodes = db_query('SELECT internal_id, stamp FROM {social_content_history} WHERE instance = :instance', array(
-        ':instance' => $instance->id,
-      ))->fetchAllKeyed(0, 1);
+      $query = db_select('social_content_history', 'sch');
+
+      // Join social_content_history against node table to avoid content types that
+      // are not social_content been deleted.
+      $query->join('node', 'n', 'sch.internal_id = n.nid');
+
+      // Set fields and conditions.
+      $query->fields('sch', array('internal_id', 'stamp'))
+        ->condition('sch.instance', $instance->id)
+        ->condition('n.type', $instance->global);
 
+      // Fetch results.
+      $nodes = $query
+        ->execute()
+        ->fetchAllKeyed(0, 1);
+
+      // Convert interval to seconds.
       $delete_date_seconds = $instance->settings['auto_delete'] * 24*60*60;
+
       foreach ($nodes as $nid => $created) {
         if (REQUEST_TIME - $created > $delete_date_seconds) {
           $nids_to_delete[] = $nid;
@@ -159,6 +171,7 @@ function social_content_delete_old_nodes() {
   }
 
   $count = count($nids_to_delete);
+
   if ($count) {
 
     // Do not delete from history, so they are not imported again.
