CAML/KQL Filter for Highlighted Content Modern Web Part

Copper Contributor

Hi All,


My organization uses SharePoint Online, and I'm trying to set up a modern page that uses the "Highlighted Content" web part with some custom CAML or KQL filtering.


What I'd like to do is:

  • Add a site column (lookup value) to the Pages library.
  • Create a modern site page with the Highlighted Content web part with a custom filter that is set to display all files/resources that share the same lookup value as the page being configured.

Users setting up this page won't necessarily be SharePoint experts, so I'm hoping once I get this working to turn this into a page template to automate the filter logic as determined by how the author tags each page.


I'm familiar with assigning the site column tot he page library, and I've seen references to CAML/KQL logic that filters by specific fields, but I haven't been able to tie it back to how the parent page is configured. Any assistance would be appreciated.



2 Replies

@AndrewWDC this is going to depend on whether you want to pull pages from multiple sites or just the same site the highlight content web part page exists in.  If it's the former, you need a KQL query.  If it's the latter, it'll be a CAML query.  You'll also need to index the site column and find its corresponding Managed Property in your search settings.  

Assuming you're looking in multiple sites, here's a KQL query that will get you all site pages:

ContentType:Site Page

now let's say you add a choice column named "PageType" and have two choices, "highlight" and "normal".  First, it needs to be indexed.  Then you need to go to your Search settings and look at Managed Properties.  Search for your column name.  In my case, the managed property is ows_q_CHCS_PageType.  So my query can now be modified as follows:

ContentType:Site Page AND ows_q_CHCS_PageType:highlight

This will show me all Site Pages in all site collections that have had the PageType set to "highlight".

Hope this helps.


@xpetecamx and @AndrewWDC - We're trying to figure this out as well. xpetecamx, your solution relies on a static value for ows_q_CHCS_PageType. I believe AndrewWDC is asking if there's a way to inject the value from the page property where the Highlighted content web part is added into the filter query. Our use case is to add a Highlighted content web part to a page that shows a list of related pages based on a custom site column. For example, all pages with the same value in a site column called Section. We don't want to have to configure every page in the Site Pages document library with a static filter value for the Sections column in its Highlighted content web part. We want the web part query to dynamically pull that filter value from the current page it's being displayed on.