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:
1: <property name="QueryOverride" type="string"><![CDATA[<Where>
2: <Or>
3: <Eq><FieldRef Name="ContentType"/><Value Type="Text">Content Type One</Value></Eq>
4: <Eq><FieldRef Name="ContentType"/><Value Type="Text">Content Type Two</Value></Eq>
5: </Or>
6: </Where>]]>
7: </property>
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.]
]]
>









Thanks Glyn, using in the ListsOverride allowed me to return items from Documents and Pages libraries
Thanks Craig Can you please provide me example as i need to Query to different content type from two different list.
Thanks
Ronak
[...] about how this can be done. For more information it’s recommended to check out his blog post: CQWP #2: Aggregating items with multiple content types. Another recommended resource for this is How we did it: mavention.nl – Part 5: Mavention RSS by [...]