CAML/KQL Filter for Highlighted Content Modern Web Part

%3CLINGO-SUB%20id%3D%22lingo-sub-1481190%22%20slang%3D%22en-US%22%3ECAML%2FKQL%20Filter%20for%20Highlighted%20Content%20Modern%20Web%20Part%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1481190%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20organization%20uses%20SharePoint%20Online%2C%20and%20I'm%20trying%20to%20set%20up%20a%20modern%20page%20that%20uses%20the%20%22Highlighted%20Content%22%20web%20part%20with%20some%20custom%20CAML%20or%20KQL%20filtering.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I'd%20like%20to%20do%20is%3A%3C%2FP%3E%3CUL%3E%3CLI%3EAdd%20a%20site%20column%20(lookup%20value)%20to%20the%20Pages%20library.%3C%2FLI%3E%3CLI%3ECreate%20a%20modern%20site%20page%20with%20the%20Highlighted%20Content%20web%20part%20with%20a%20custom%20filter%20that%20is%20set%20to%20display%20all%20files%2Fresources%20that%20share%20the%20same%20lookup%20value%20%3CEM%3E%3CSTRONG%3Eas%20the%20page%20being%20configured%3C%2FSTRONG%3E%3C%2FEM%3E.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EUsers%20setting%20up%20this%20page%20won't%20necessarily%20be%20SharePoint%20experts%2C%20so%20I'm%20hoping%20once%20I%20get%20this%20working%20to%20turn%20this%20into%20a%20page%20template%20to%20automate%20the%20filter%20logic%20as%20determined%20by%20how%20the%20author%20tags%20each%20page.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20familiar%20with%20assigning%20the%20site%20column%20tot%20he%20page%20library%2C%20and%20I've%20seen%20references%20to%20CAML%2FKQL%20logic%20that%20filters%20by%20specific%20fields%2C%20but%20I%20haven't%20been%20able%20to%20tie%20it%20back%20to%20how%20the%20parent%20page%20is%20configured.%20Any%20assistance%20would%20be%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1481190%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New 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.

 

Thanks!

1 Reply

@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.