Live Filter – set default filter (activate a filter at the beginning)

By default, the “All” option is active for the Checkbox, Radio, Dropdown, Button types of Live Filter.
To activate another option for these types at the beginning, please add this code to Custom JS field in Content Views >> Settings page:

/* Live Filter - set default filter */
if (!window.location.search) {
    var term_slug = 'SELECTED_OPTION_HERE', view_id = 'VIEW_ID_HERE';
    var $el = $('[value="' + term_slug + '"]', '[data-sid="' + view_id + '"]');
    $($el).attr("checked", true);
    $($el).attr("selected", true);
    $($el).trigger('change');
}

then:

  • replace SELECTED_OPTION_HERE with the value you want to select by default.
    To get that value, please:
    + open the page with Live Filter
    + select the option you want to select by default
    + the URL in browser’s address bar will be changed accordingly and end with:

    /?NAME=VALUE
    

    + copy the VALUE to replace the SELECTED_OPTION_HERE in the code.

    For example, you show categories as filters and want to select the “Business” option by default.
    When you select that option, the URL ends with: /?tx_category=business.
    Then business is VALUE you should copy and put in the code.

  • replace VIEW_ID_HERE with ID of your View.

Best regards,