PnP Modern search: Set refiners in the URL
- Kasper Larsen
- Aug 16, 2023
- 1 min read
The PnP Modern Search Filter web part supports deep URL linking, so if you provide the correct URL both the Search text and selected filters can be activated once the page loads:

However, getting the correct URL can be tricky. The recommended approach is to set the search text and the relevant Filters and then grab the browser URL. It will look like this:
https://[Tenant].sharepoint.com/sites/PnPModernSearch/SitePages/Filters-read-from-url-are-not-set-in-the-filter-web-part--3157.aspx?q=cmo&f=%5B%7B%22filterName%22%3A%22RefinableString09%22%2C%22values%22%3A%5B%7B%22name%22%3A%22CMO%22%2C%22value%22%3A%22%C7%82%C7%82434d4f%22%2C%22operator%22%3A0%2C%22disabled%22%3Afalse%7D%5D%2C%22operator%22%3A%22or%22%7D%5D#
The components are: the URL to the page + the q section + the f section.
The q section is just the text to be applied in the Search Box.
The f section is the Filter settings. It looks pretty messy, but this PowerShell snippet will clean it up:
$url = Read-Host "Enter URL"
$pageURL = $url.Substring(0, $url.IndexOf("?"))
$filterURL = $url.Substring($url.IndexOf("?")+1)
$filterURL = $filterURL.Replace("%5B", "[")
$filterURL = $filterURL.Replace("%7B", "{")
$filterURL = $filterURL.Replace("%22", '"')
$filterURL = $filterURL.Replace("%3A", ":")
$filterURL = $filterURL.Replace("%2C", ",")
$filterURL = $filterURL.Replace("%5D", "]")
$filterURL = $filterURL.Replace("%7D", "}")
$filterURL = $filterURL.Replace("%C7%82%C7%82", "ǂǂ")
$newUrl = $pageURL + "?" + $filterURL
$newUrl
And once cleaned up it looks like this:
f=[{"filterName":"RefinableString09","values":[{"name":"CMO","value":"ǂǂ434d4f","operator":0,"disabled":false}],"operator":"or"}]
The value tag above is the Filter Token, and you will be able to find those using the SP Search Query Tool.








Hello, thanks a lot for this article that answer to my need : passing filters to the search module within the URL
However, I still have a technical problem: I can forge the URL with the encoding, but in pnp - search results, I don't see at all what settings allows me to retrieve the contents of the "f" field of the URL and make this webpart understand that it is indeed a filter (and not the content of the query). Actually, the URL filter is not applied at all. And even more, when I select values from the "search filters" webpart, the URL does not contain the selected values at all. However, the filters are applied to the "result"…
where does"ǂǂ434d4f come from ?