SharePoint: Content Query Web Part Customizing the Query


Recently I’ve been customizing Content Query Web Parts (CQWP) whereby I override the query and supply my own CAML query. The basic steps involved in doing this are;

  1. Author the Web Part using the UI
  2. Export the Web Part using the UI
  3. Customize the Web Part .webpart file
  4. Import the customized Web Part back into SharePoint

Some of these Web Parts were configured to query by Content Type, such that the Web Part property “ContentTypeName” is given a specific value as shown below;


    <property name="ContentTypeName" type="string">Period View Item</property>

Prior to customizing the CQWP query with CAML, such a Web Part worked fine. So having exported the Web Part I provided a custom CAML query using the “QueryOverride” property;


  <property name="QueryOverride" type="string"><![CDATA[<Where>...</Where>]]></property>

After importing the Web Part back into SharePoint I noticed that it would return results for other Content Types also. To work around the problem I modified the CAML query to restrict the results to the Content Type in question, like so;


  <Where><And><And><Eq><FieldRef Name="ContentType" /><Value Type="Choice">Period View Item</Value></Eq>......</And></And></Where>

I suspect this is by design rather than a bug, however the CQWP documentation indicates that the query by Content Type feature is a filter rather than part of the query, as this article aludes to.

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s