How can I limit the exposed filters to only display values for which content exists?
This works for me:

function mymodule_form_views_exposed_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if (isset($form['tid']['#options'])) {
    foreach ($form['tid']['#options'] as $key =&gt; $value) {
      // Limit to numeric keys to exclude the 'All' option.
      if (is_numeric($key)) {
        // Start database query.
        $query = \Drupal::database()-&gt;select('taxonomy_index', 'ti');
        $query-&gt;fields('ti', ['nid']);
        $query-&gt;condition('ti.tid', $key);
        $nodes = $query-&gt;execute()-&gt;fetchAssoc();
        // Remove option if term has no instance.
        if (!$nodes) {
          unset($form['tid']['#options'][$key]);
        }
      }
    }
  }
}


You will probably need to adjust the 'tid' in $form['tid']['#options'] to the Filter identifier as defined in your views' filter settings.
Credits for the quick and efficient database query go to https://drupal.stackexchange.com/a/219368/25154.