// JS Variables

FWP

The FWP object gets passed to the server on each refresh. It contains all the necessary information for generating the template, facets, pagination, etc.

var FWP = {
    "facets": {
        "vehicle_type": [], // no selections for this facet
        "make": ["audi"] // one selection
    },
    "template": "cars",
    "settings": {
        "pager": {
            "page": 1,
            "per_page": 4,
            "total_rows": 21,
            "total_pages": 6
        },
        "num_choices": {
            "vehicle_type": 5,
            "make": 1
        },
        "labels": {
            "vehicle_type": "Vehicle Type",
            "make": "Make"
        }
    },
    "is_reset": false,
    "is_refresh": false,
    "is_bfcache": true,
    "auto_refresh": true,
    "soft_refresh": false,
    "frozen_facets": {},
    "facet_type": {
        "vehicle_type": "radio",
        "make": "checkboxes"
    },
    "loaded": true,
    "jqXHR": {}, // jQuery ajax request data
    "extras": {
        "sort": "default", // load the sort box
        "pager": true // load the pager
    },
    "paged": 1
};

Browse to our Cars demo, open your browser console, and type FWP to see actual data.

FWP Methods

FWP.reset() // reset everything
FWP.reset('region') // reset the "region" facet
FWP.reset('region', 'midwest') // clear the "midwest" choice

// Force a refresh
FWP.refresh()

// Parse the URL hash to populate FWP.facets
FWP.load_from_hash()

// Parse the facet HTML values to populate FWP.facets
FWP.parse_facets()

// Update the URL hash based on the values in FWP.facets
FWP.set_hash()

// Get the URL variable string
var str = FWP.build_query_string();

FWP_HTTP

All requests happen via AJAX. For URI and GET variables to be available, they’re stored in FWP_HTTP. Use $this->http_params within your FacetWP template to access.

/*
Example URL:
http://yoursite.com/places/virginia/?county=loudoun&city=leesburg
*/
var FWP_HTTP = {
    'uri': 'places/virginia',
    'get': {
        'county': 'loudoun',
        'city': 'leesburg'
    }
};