Search URL parameters query [duplicate]

Your query variable country is not defined, its not part of the standard query_vars set by WordPress, where as both monthnum and year are and that’s why they work and the former does not.

So you need to add your query variable into the mix, try the following;

function new_query_var() {

    global $wp;
    $wp->add_query_var('country');

}

add_filter('init', 'new_query_var');

Also, it appears that your foreach is checking for the existing of this query variable and hence since its not set (e.g. isset) then it fails the conditional check.