I believe you can add the following to the theme’s functions.php & visit /courses/?topics=foo,bar
to get the results you’re looking for:
<?php
/**
* Custom search-query with taxonomy filter
*/
function wpse373353_search_query( $wp_query ) {
// exit early if this isn't that main loop on the front-end of the site
if ( ! $wp_query->is_main_query() || is_admin() ) {
return;
}
if ( $wp_query->get( 'post_type' ) === 'courses' ) {
if ( ! empty( $_GET['topics'] ) ) {
$topics = $_GET['topics'];
foreach ( $topics as $key => $val ) {
$topic_terms[ $key ] = sanitize_key( $val );
}
}
if ( ! empty( $topic_terms ) {
if ( ! $tax_query = $wp_query->get( 'tax_query' ) ) {
$tax_query = [
// change to OR instead of default AND here if desired
// 'relation' => 'OR',
];
}
// add the topics tax-query
if ( ! empty( $topic_terms ) ) {
$tax_query[] = [
'taxonomy' => 'topics',
'field' => 'slug',
'terms' => $topic_terms,
];
}
// save the modified wp_query
$wp_query->set( 'tax_query', $tax_query );
}
}
}
// hook into the pre_get_posts action
add_action( 'pre_get_posts', 'wpse373353_search_query' );