Content Type Filters for SharePoint Online

Reading Time: 5 minutes

[Validated and Updated July 2024] A reminder that the same content type filters that can be used in a search web part that is being described in this post can also be used to automatically apply a retention label by using the content type filter as the Keyword Query Language (KQL) condition in an auto-apply retention label policy.

Reference: Auto-apply labels to content with keywords or searchable properties

If you’ve created a content type in SharePoint, you may find yourself needing to filter on it in a search web part (Highlighted Content web part) or needing to apply a retention label on content based on it. Being able to do this is particularly important if the content type is in use across many sites in your tenant.

Although filtering content types in one specific library may not be necessary, think big picture and overall use-case. What if we had corporate policies in 3 different sites on our tenant as follows:

  • Lending policies stored in the Lending site
  • HR policies stored in the HR site
  • Travel policies stored in the Travel site

And what if policies in the above sites all used the Corporate Policy content type to store their policies? Or… what if the above sites all created their own child Policy content types (Lending Policy, HR Policy, Travel Policy) based off the parent Corporate Policy content type? How could we roll-up all policies of type Corporate Policy for our tenant onto 1 page in a highlighted content web part? Or… how would we apply a retention label on all content inheriting from the Corporate Policy content type? This is completely doable, however you need to know how you want to roll them up or apply the label before you start.

There are 3 managed properties you can use to filter by content type. In every Microsoft 365 tenant, these are the managed properties automatically generated for you relating to content types.
BaseContentTypeManagedProperties

They can be used as-is and they do not need to be mapped to one of the RefinableString managed properties like custom properties do. Each of the 3 content type properties contains very different content values. Understanding the values stored in each of them is key to building a correctly formatted query.

Here’s an example of the values found in each of the 3 above managed properties:

  • ContentType: application/pdf Project Document
  • ContentTypeId0x010100A9FCC3401E34944EB9278130E0DC5BB7…
  • SPContentTypeProject Document

I’ll showcase each of the 3 above managed properties in this post.


ContentType managed property

The value in this managed property contains a combination of the mime type name (E.g., application/pdf) and the content type name (Project Document). For this reason, you must use the qualifier Contains to filter using only the friendly name of the content type. My recommendation is to use the SPContentType managed property instead if you want to filter by the friendly name alone, however the ContentType managed property filter will certainly work.

Use the ContentType managed property with caution if you have similarly-named content types which may cause more matches than expected. (Example: content type names of Corporate Policy USA and Corporate Policy Australia will BOTH be returned if you have a filter like ContentType:”Corporate Policy” since that string is contained in both content types.

Here’s the Highlighted Content web part filter required for the ContentType property.
ContentTypeFilter

In most cases, my recommendation when auto-applying a retention label is to use the SPContentType managed property and the equals sign instead of the ContentType managed property and the contains (colon) operator. The former is more explicit and a safer method to use to ensure content won’t be mislabeled.

Example: SPContentType=”<your content type name>”

In some cases, the contains (colon) operator may also give you the results you want with the SPContentType managed property, but this depends on your content type names.

Note: If you’ve created a child content type (Example: HR Policy inheriting from Corporate Policy) and try to use the parent content type name as a filter, it will not return any results for content of the child content type. To do this, use the ContentTypeId filter option discussed below.


ContentTypeId managed property

You can use this managed property if the content type ID has been controlled and therefore consistently configured across all sites it exists in. Ways to do this are:

  • create and publish the content type via the Content Type Hub which ensures the ContentTypeId is the same across all site collections
  • create the content type using custom code and thereby controlling the ContentTypeId programmatically
  • using Site Scripts and Site Designs, explicitly specify the content type Id in the site script action (image)

SiteDesignContentTypeId

If the above techniques are not used, the ContentTypeId will be different in each site it’s created in (even if the content type name is the same) and therefore will not work as a cross site filter.

One important thing to know about filtering the Highlighted Content web part by ContentTypeId, is to ensure you are using the Contains qualifier and insert a wildcard after the end of the Id. This is for 2 reasons:

  • it ensures any library with content using the content type will be returned since once a content type is applied to a list/library, additional characters are appended to the end of the ContentTypeId
  • if a child content type has been created based off a parent content type and you want to filter on the parent content type, this filtering technique will return all content type content inheriting from the parent, including all children.

Example: If you’ve created a child content type (Example: HR Policy inheriting from Corporate Policy) and use the parent content type Id as a filter with a wildcard appended to the end, it will return all results for Corporate Policy and anything inheriting from it, including HR Policy.

Here is the Highlighted Content web part filter:

ContentTypeIdFilter… where the value for ContentTypeId in this example has an asterisk (wildcard) appended to the end:

0x010100A9FCC3401E34944EB9278130E0DC5BB7*

This same wildcard technique can be used to apply a retention label as well. However, if you do, it will not be as easy to tell which content types are included in the label policy since all you have to go by is an Id. It does however have the added benefit of including any future child content types inheriting from the parent if that is a requirement.


SPContentType managed property

The value in this managed property is the “friendly” name of the content type and, unless requirements dictate a ContentTypeId filter is required, is my preferred method for filtering content based on content type and auto-applying a retention label. For example, Project Document or Backlog Item. If you’ve manually created content types or haven’t controlled the Id of the content type, you must use either this managed property or ContentType to filter by content type name.

Here’s the Highlighted Content web part filter options required for this property. Note, you can use either the qualifier Contains or Equals to return results since the managed property is the exact name of the content type.


My thoughts

An important reason why Information Architecture planning is important is to ensure you will be able to surface relevant content to the right audience when you need to. Content Types have been around for a long time and will continue to be one of the hallmarks of SharePoint content management. Make sure you know how you’ll want to leverage content types in your organization and that you’re building solutions to be able to deliver results whether the content types were configured with manual or automated provisioning methods.

Additionally, if you want to be able to apply a retention label to content in an automated way, content types are a great way of accomplishing this!

Thanks for reading.

-JCK


Photo by Sharon McCutcheon from Pexels

6 comments

  1. Hi Joanne,

    Thanks for the great article.

    Small question for you. In the case of an intranet of publication ( 20+ Communication Site) where there is no need to retention and advanced IA scenario, where metadata is mainly on document and page for displays purpose and search refinements.

    Do you think we should add one content type for document and page (ex: Client Name Document and Client Name Page) on every site collection for the future proofing of the solution, or we can just create (via pnp) the site column and add them to the require library on each site ?

    In the past my first thought would be the “content type way” but taking into consideration that Microsoft is making a lot more change in SharePoint as before. That they are making the creation of new list column very easy to add without CT. Also considering that adding content type imply removing the other CT for a best user experience… I’m not so sure that it is the way to go in my simple publication scenario.

    For example, I’m wondering the impact of creating a “Client Name Page” content type, If Microsoft add new feature like the “display date” of a news as part of the default Page Content type. Would it be more “future proof” if we create site column and add them via script at the list level ?

    Thank for your help

  2. Hi Joanne,

    again a wonderful article that helped me a lot!
    Unfortunately it doesn’t work for my case: I created a new content type for news “company news”. CN has an expiration date. I added the expiration date in the search schema to “refinabledate00” –> this works, I can filter the webpart by date.

    I also added another filter like the one above, meaning “filter the news by date AND by content type CN”. Each filter for itself will work, unfortunately both filters together won’t work.

  3. Hi Christian,
    I do compound filters like this all the time. If you’re in a highlighted content web part make sure you go to the custom or advanced setting (I’m not in front of my computer, can’t remember what the link name says) to enter your advanced query directly. You can’t have an AND condition if you use the non-advanced way, it implicitly OR’s them together.
    Hope that helps!
    -JCK

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.