Change the Selected Default Category

To change the selected default category, use the wpsl_dropdown_category_args filter. You can configure the filter so that it always sets the same default category, or you can make it more dynamic by including the category ID in a link to the store locator page.

Whichever way you choose, the first thing you need to find is the ID of the category that you want to set as selected. You can find this information on the Store Locator > Store Categories page.

Open the category you want to set as selected, and look for this part in the URL in your browser bar, tag_ID=xxxx. The number after tag_ID is the ID you need.

Always Use the Same Default Category

Replace 1 with the ID of the category you want to use in the code example below, and place it in the functions.php inside your active theme folder.

Set the Default Category Through a Link

If you want to set the default category through a link, then you will have to include the category ID or name in the URL.

This structure will set the default category by ID.
http://yourdomain.com/your-store-locator-page/?wpsl_cat_id=the-category-id

You can find the category ID by going to the Store Locator -> Store Categories page, click on the category you want to use and look for tag_ID=xxx in the URL bar. xxx is the ID of the category you need to include in the URL.

This structure set the default category by name.
http://yourdomain.com/your-store-locator-page/?wpsl_cat_name=the-category-name

Set the Selected Category

The next step is to make sure that the parameter passed through the link is actually used to set the selected category.

This example uses the category ID to set the default category.

add_filter( 'wpsl_dropdown_category_args', 'custom_dropdown_category_args' );

function custom_dropdown_category_args( $args ) {
    
    if ( isset( $_REQUEST['wpsl_cat_id'] ) && $_REQUEST['wpsl_cat_id'] ) {
        $args['selected'] = (int) $_REQUEST['wpsl_cat_id'];
    }
    
    return $args;
}

This example uses the category name to set the default category.

add_filter( 'wpsl_dropdown_category_args', 'custom_dropdown_category_args' );

function custom_dropdown_category_args( $args ) {

    if ( isset( $_REQUEST['wpsl_cat_name'] ) && $_REQUEST['wpsl_cat_name'] ) {
        $cat = get_term_by('name', $_REQUEST['wpsl_cat_name'], 'wpsl_store_category');

        if ( $cat ) {
            $args['selected'] = (int)$cat->term_id;
        }
    }

    return $args;
}

For the code to work you need to place it in the functions.php inside your active theme folder.