As with my earlier post CQWP #1: Aggregating items from the last 7 days, it is sometimes a requirement to configure the Content Query Web Part beyond that which is possible through the UI and the browser. One such example of this is configuring the CQWP to aggregate items from different content types.
The recommended approach here is to use parent/child relationships for the content types if possible. For example it could be possible to have a parent content type inheriting from the out-of-the-box Document content type called Project Document. Then any actual project documents where a content type is required could inherit from this, such as a word Project Information Document or an excel Financial Tracking Spreadsheet.
This approach is only valid assuming that the content types share a base content type, such as Document in the example above. Another scenario could be to have two content types that are actually related, but with different base content types – and this is where it’s necessary to go beyond what is possible from the UI by using the QueryOverride property of the web part. The steps to implement this are broadly:
- Add and configure a CQWP to a page
- Export the web part
- Locate the property QueryOverride in the exported web part
- Insert a CAML query for this property
- Save and import the web part
The query we want to add to the web part needs to say ‘use this content type OR this content type’ and so the lines we need to add to the properties of the web part are:
The screenshots below shown an example of a modified CQWP returning items from different content types (indicated by simply naming the items after the content type!), and a section of the modified properties of the web part.
Note: In the example above it assumes that both of the content types are coming from the same library or type of library – and therefore this can be configured in the UI of the web part. However it may also be necessary to use the ListsOverride property to specify a base type of library for the query. [One thing I’ve not been able to work out is how to use the ListsOverride property to aggregate from different list base types.]]] >