$meta_query = [];
if (!empty($_GET['specialization'])) {
$meta_query[] = [
'key' => 'specialization',
'value' => sanitize_text_field($_GET['specialization']),
'compare' => '='
];
}
if (!empty($_GET['location'])) {
$meta_query[] = [
'key' => 'location',
'value' => sanitize_text_field($_GET['location']),
'compare' => '='
];
}
$args = [
'post_type' => 'doctor',
'posts_per_page' => -1,
'meta_query' => $meta_query
];
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
// (existing card rendering code here)
endwhile;
wp_reset_postdata();
else :
echo 'No doctors found with your filters.
';
endif;