How to get CGI variables?

First off, these aren’t CGI variables, they’re query string arguments.

WordPress, by default, will remove any query arguments that it doesn’t recognize. So you need to register them with WordPress and then pull them back out of the query.

First, add your new query variable:

function wpa_48528_vars( $vars ) {
    $vars[] = 'filter';

    return $vars;
}
add_filter( 'query_vars', 'wpa_48528_vars' );

Now, get the data back out:

function wpa_48528_get_filter() {
    global $wp_query;

    if ( array_key_exists( 'filter', $wp_query->query_vars ) ) {
        return $wp_query->query_vars['filter'];
    }

    return '';
}