- Help Center Home
- Getting started
- Introducing FacetWP
- Installation and updates
- FAQ
- How it works
- What are facets?
- Facet types
- Indexing
- Listing templates
- Extras & integrations
- Add-on features and extras
- Using FacetWP with …
- Built-in integrations
- Advanced Custom Fields
- WooCommerce
- SearchWP
- WP-CLI
- Add-on integrations
- Bricks
- Elementor
- Beaver Builder
- WP Recipe Maker and Tasty Recipes
- Relevanssi
- WPML and Polylang
- Pods
- Meta Box
- Flatsome (theme)
- External integrations
- Listify (theme)
- Listable (theme)
- WPGraphQL
- Document Library Pro
- Tips & tricks
- WooCommerce plugins
- WordPress multi-site
- WP All Import
- WebToffee Import Export
- WP Job Manager
- Easy Digital Downloads
- EDD Reviews
- Intuitive Custom Post Order
- Custom Taxonomy Order
- Post Types Order
- Genesis framework
- WP External Links
- ElasticPress
- Caching & hosting
- WP Rocket
- Cloudflare
- New Relic
- WP Engine
- Fast Velocity Minify
- Incompatibilities
- Incompatible plugins
- Troubleshooting
- Troubleshooting guide
- Using the right query
- Common issues
- Get support
- Developers
- Hooks reference
- JavaScript reference
- Shortcodes reference
- FacetWP REST API
- How FacetWP works
- The FacetWP URL
- FacetWP speed and limits
- Tutorials
- Code snippets
- Changelog
How to pass authentication data through REST API requests
By default, the WordPress REST API doesn’t pass along authentication data.
If your FacetWP template or customization code depends on the currently logged-in user (e.g. with is_user_logged_in()
, you’ll run into issues when an AJAX refresh is triggered.
Fortunately, there’s an easy workaround: add the following code to your (child) theme’s functions.php:
/*
Please note that caching may interfere with the NONCE,
causing ajax requests to fail. Please DISABLE CACHING for facet pages,
or set the cache expiration to < 12 hours!
*/
add_action( 'wp_footer', function() {
?>
<script>
document.addEventListener('facetwp-loaded', function() {
if (! FWP.loaded) { // initial pageload
FWP.hooks.addFilter('facetwp/ajax_settings', function(settings) {
settings.headers = { 'X-WP-Nonce': FWP_JSON.nonce };
return settings;
});
}
});
</script>
<?php
}, 100 );