Custom module wiped out all content of type
Your query seems to be ok, irrespective of drupal version it should work. Here are the few pointers to debug.


Check the query output, is your query returning all nodes of type 'recent' without filtering by created

function delete_old_nodes_cron() {
  $query = \Drupal::entityQuery('node')
      -&gt;condition('created', strtotime('-2 year'), '&lt;=')
      -&gt;condition('type', 'recent');
  $nids = $query-&gt;execute();
  dpm($nids);
}

Make sure for your recent created nodes created time is not altered somewhere.