Contact us


Using KQL To Force “AND” in SharePoint Highlighted Content Web Parts

By Rhia Wieclawek on September 22, 2021

Certain restrictions in SharePoint Online web parts can have limited functionality, getting in the way of what you are trying to achieve. The SharePoint Highlighted Content Web Part is a great example of this, as it does not allow the user to combine an “AND” on managed properties. In this tutorial, we will demonstrate how to do so.

In order to force this combination, first go to the “Custom Query” capability of the SharePoint Highlighted Content Web Part. Here, you can build your own query through the Keyboard Query Language (KQL).

For example, if you are building a web part that will show news that is set as a highlight, but you only want to show news types of “CEO” or “Learning”, this cannot be achieved due to the restrictions in SharePoint’s out of the box news web part. Any managed property will become an “OR”. To make sense of this, the following graph is a great source to gain a better understanding of how Highlighted Content Web Part logic works.

This “OR” restriction means it would be a highlight OR it would be a Learning OR CEO news. It would continue by using only one of these types.

Important information before continuing:

  • “IsDocument:1” means that you are looking for a document.
  • “PromotedState:2” means you are looking for news.

In the above scenario, the first step is setting up the news you are looking for (PromotedState:2).

Next, identify the managed property name of the field. In this example, you know that the column name is “News Type“, as that’s what you see in your library and where you set the news type when posting news.

To find the managed property, go to the gear icon > site contents > site settings > schema.

Once there, you will type a part of our column name. The managed property name will appear, as seen below. Our “News Type” is actually “owstaxIdNewsType” – this is SharePoint’s internal name that it shares across the sites for tracking purposes.

Next, update your query:  (PromotedState: 2  AND  owstaxIdNewsType:)

Now you are able to input what you would like the News Type to be in the query. To do that, first append the text “GP0|#“, this prepares the query that you will be looking for a specific term from a term store.

(PromotedState: 2  AND  owstaxIdNewsType:GP0|#)

Now, go into the term store, browse for your term, and grab it’s GUID and it’s term name. The term name in this example is “Learning”.

In the term store, click on the term. You will find the GUID at the very bottom.

The query gets updated again, but note the specifics of this one: the GUID, then the term.

(PromotedState: 2  AND owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”)

Repeat the action for the “CEO” Updates, but first, to be clear in your query that it is “Learning” OR “CEO” and the other pieces are non-negotiable, put it between new brackets.

(PromotedState: 2  AND (owstaxIdNewsType:GP0|#c6bcf9b0-f056-41fb-a877-c490aee72a83:”CEO”) OR (owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”))

Finally, only show items where “HighlightNews” is equal to Yes. If you recall when originally looking for the NewsType managed property, you’ll notice Highlight also appeared there. Put this at the beginning of your query, with the other non-negotiable (the PromotedState): This AND This (this OR this)

(PromotedState: 2 AND HighlightNewsOWSCHCS: (owstaxIdNewsType:GP0|#c6bcf9b0-f056-41fb-a877-c490aee72a83:”CEO”) OR (owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”))

The final touch is adding the “Yes”, and, since the Highlight column is just a choice column, not managed metadata, no GUID is needed.

(PromotedState: 2  AND HighlightNewsOWSCHCS: “Yes” (owstaxIdNewsType:GP0|#c6bcf9b0-f056-41fb-a877-c490aee72a83:”CEO”) OR (owstaxIdNewsType:GP0|#cf880322-06ba-4066-9bf5-375b4d18314b:”Learning”))

Putting this into the KQL Query box in the Highlighted Content Web Part will do the trick!

​​​​​​​The configured web part is below.

And here is an example of our beautiful published SharePoint news web part showing posts with the properties “CEO” and “Learning.”


Rhia Wieclawek - Elantis Business Process Automation Practice DirectorRhia Wieclawek – Director, Business Process Automation

Rhia is a Business Process Automation expert and one of the few Nintex virtual Technology Evangelists (vTE) in the world. Her experience defining, implementing, and enhancing processes, governance, and Information Architecture has garnered industry recognition.  Rhia has spoken at industry events throughout Canada and the United States.

object(WP_Term)#2405 (16) { ["term_id"]=> int(5) ["name"]=> string(4) "Tech" ["slug"]=> string(4) "tech" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(5) ["taxonomy"]=> string(8) "category" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(57) ["filter"]=> string(3) "raw" ["cat_ID"]=> int(5) ["category_count"]=> int(57) ["category_description"]=> string(0) "" ["cat_name"]=> string(4) "Tech" ["category_nicename"]=> string(4) "tech" ["category_parent"]=> int(0) } Tech|November 23, 2021

Create a Custom Chatbot Without Code

Create a custom chatbot using services like Microsoft Virtual Power Agents, without code or a team of skilled developers.

object(WP_Term)#2403 (16) { ["term_id"]=> int(5) ["name"]=> string(4) "Tech" ["slug"]=> string(4) "tech" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(5) ["taxonomy"]=> string(8) "category" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(57) ["filter"]=> string(3) "raw" ["cat_ID"]=> int(5) ["category_count"]=> int(57) ["category_description"]=> string(0) "" ["cat_name"]=> string(4) "Tech" ["category_nicename"]=> string(4) "tech" ["category_parent"]=> int(0) } Tech|October 18, 2021

What is the Citizen Development Model: Another Benefit of the Low-Code/No-Code Movement

Promote collaboration and empower Citizen Developers to solve business problems by creating applications using low-code/no-code technology.

holding a mobile phone
object(WP_Term)#2407 (16) { ["term_id"]=> int(5) ["name"]=> string(4) "Tech" ["slug"]=> string(4) "tech" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(5) ["taxonomy"]=> string(8) "category" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(57) ["filter"]=> string(3) "raw" ["cat_ID"]=> int(5) ["category_count"]=> int(57) ["category_description"]=> string(0) "" ["cat_name"]=> string(4) "Tech" ["category_nicename"]=> string(4) "tech" ["category_parent"]=> int(0) } Tech|August 20, 2021

How Low-Code Applications Like Power Apps are Changing the Game

Low-code automation has disrupted traditional forms of custom coding. What are the benefits of shifting to low-code applications?