Admin view: filter posts by whether they have specific taxonomy attached

After a lot of fiddling I managed to get the functionality working.

First I add custom dropdown boxes for ‘Regional’ and ‘International’ using wp’s action restrict_manage_posts. Then I set up a custom function that will be added to wp’s filter parse_query.

In that function:

// type is the name of the select field 
if($_GET['type'] == 'Regional'){

  // get terms as WP_Term objects
  $regional_terms_objects = get_terms( array(
    'taxonomy' => 'regional',
    'hide_empty' => false,
  ));

  // convert them to an array of slugs
  $regional_terms_objects = array();
  foreach ($regional_terms_objects as $regional_terms_object){
    $regional_terms[] = $regional_terms_object->slug;
  }

  // filter the posts by all terms for taxonomy
  $tax_query = array(
    'taxonomy' => 'event-categories',
    'field' => 'slug',
    'terms' => $regional_terms
  );
}else{
   // the same stuff for 'International'
}
// add the query
$query->set('tax_query', $tax_query);

That way I can choose between ‘Regional’ and ‘International’ in the admin view and see only the events that belong to the chosen taxonomy.
I hope someone can use that 🙂